(ref)vue遍歷ref或動態或多層遍歷動態ref


<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]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM