<el-input ref="'workedInfoRef' + scope.$index" //scope.$index如果是for循環可以是index,這里用了el-table的index
></el-input>
//獲取
this.$refs[`workedInfoRef${i}`];
//input手動焦點
this.$refs[`workedInfoRef${i}`].focus();
如果是for循環直接遍歷,下面的ref是個數組
<li v-for="(list, index) in tagList" :key="index" ref="tagItem">{{list.value}}</li>
this.$refs.tagItem[0].style.backgroundImage = `url(${xxx})`
雙層for循環遍歷
三. 雙循環動態設置ref 設置【:ref="‘xxx’+id"】或【:ref="‘xxx’+index"】 <div v-for="(item,index) in topicList" :key="index"> <el-carousel-item v-for="(son,i) in item.questionList" :key="index+i"> <topic :ref="'topicRef'+son.bId"></topic> //或也可以用索引. 用一個索引會重復,如下 //<topic :ref="'topicRef'+(i+index)"></topic> </el-carousel-item> </div> 獲取 eval("that.$refs.tagItem" +(x+index))[0] 或 eval("that.$refs.topicRef" +(ele.bId))[0]