我想通过ref获取下面box元素 在mounted里面 通过$nextTick获取不到 用定时器或者用getElementById这些都获取不到 只有最外面的容器floor可以获取 里面的子元素都获取不到,是因为v-for的原因吗
<div class="floor">
<div class="floorA" v-show="item.lists.length" v-for="item in productCategories">
<div class="title clearfix">
<p class="prTitle">{{item.prTitle}}</p>
<router-link :to="{path:'/invest',query: {productCategoryId: item.productCategoryId}}">更多 > ></router-link>
</div>
<ul class="bidList clearfix">
<li
v-for="(list, index) in item.lists"
:class="{btwo: index % 3 === 1}"
v-if="index < 3"
>
<h2>{{list.name}}</h2>
<div ref="box" style="width:190px;height:190px;"></div>
</li>
</ul>
</div>
</div>
mounted() {
this.$nextTick(() => {
var box = this.$refs.box
console.log(box)
})
},
建议用通过class获取元素集合
:ref用法上类似与id选择器
.$nextTick无法获取的话
可以使用watch监听