(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]
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步