是否可以通过使用元素的refs索引访问嵌套v-for循环中的元素?我的意思是,我试图将文本框的焦点放在嵌套的v-for循环中,该循环用于通过其refs索引进行访问。它适用于单个v-for循环,但不适用于嵌套。
有关更多详细信息,这是我的循环结构:
这有效
<div v-for="(comItem,index) in commentItems" :key="comItem.commentId">
<textarea ref="addRep" ></textarea>
</div>
this.$nextTick(() => {
this.$refs.addRep[index].focus()
});
这不起作用
<div v-for="(cont,i) in contentItems" :key="cont.contentId">
...
<div v-for="(comItem,index) in commentItems" :key="comItem.commentId">
<textarea ref="addRep" ></textarea>
</div>
</div>
this.$nextTick(() => {
this.$refs.addRep[index].focus()
});
Or
this.$nextTick(() => {
this.$refs.addRep[i].focus()
});
具有嵌套的html v-for循环结构。焦点将随处跳动。对于遇到这种情况的任何人。如果您知道解决方案,请协助我。谢谢。