获取动态循环的的标签
<div>
<span v-for="(item,index) in list" :key="index" :ref="'spanRef' + index" :id="'spanRef' + index">{{item.label}}</span>
</div>
list: [
{
id: 1,
label: 1
},
{
id: 2,
label: 2
},
{
id: 3,
label: 3
},
]
mounted() {
this.$nextTick(() => {
for (let i = 0; i < this.list.length; i++) {
const element = this.list[i];
console.log('i====>', this.$refs['spanRef' + i]);
console.log('document===>', document.getElementById("spanRef" + i));
}
})
},
本文来自博客园,作者:云霄紫潭,转载请注明原文链接:https://www.cnblogs.com/0520euv/p/15802346.html