当我在 v-for 中设置它时,我无法访问我的 ref

问题描述

我有其他可以访问的 ref,但是当我在 v-for 中设置我的 ref 并尝试访问它时,它返回 undefined。我已经阅读了 vue 文档并尝试了在 stackoverflow 中发布的许多可能的解决方案,但似乎没有一个我有用。

即使我使 ref 唯一,仍然返回 undefined。

:ref="`hexagon${rowNum}${xShapeIndex}`"

<template lang="pug">
  div(ref="container")  
      v-stage(:config="stageConfig" ref="stage")
        v-layer 
          //- rowNum starts at 1          
          div(
            v-for="rowNum in numberOfRows"
            :key="rowNum"
            )
            div(
              v-for="(service,xShapeIndex) in filteredServices.slice((rowNum - 1) *          
                         numberOfXShapes,rowNum * numberOfXShapes)"
              )
              v-regular-polygon(
                ref="hexagon"
                @mouseenter="isHovering = true"
                @mouSEOut="isHovering = false"
                @click="redirectToEnvView(service)"
                :config="polygonConfig(service,xShapeIndex,rowNum - 1)"
                )

mounted() 
      //hexagon animation
      const period = 5000;
      // in ms

      const vm = this
      vm.$nextTick(()=> 
        console.log(vm.$refs.container) // OK,returns somthing
        console.log(vm.$ref.stage) // OK,returns something
        console.log(vm.$refs.hexagon) //return undefined 
      )
     

    },

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)