最重要的就是用eval函数
在Vue中,eval函数是JavaScript中的一个内置函数,用于将字符串作为代码进行解析和执行。
具体场景:
在一个循环里,要获取input,获取input焦点
<el-popover v-model="visiblePerson[index]" @show="handleInputFocus(index)">
<el-input :ref="'autoFocusInput'+index"></el-input>
</el-popover>
handleInputFocus(index) {
this.$nextTick((_) => {
let ref = eval('this.$refs.autoFocusInput' + index)[0]
ref.focus();
})
},
eval函数非常强大,平时对eval函数的应用很少,所以之前我一点都不知道这个函数的作用,但是对于这里还是很有效的。
eval函数用法
eval(string)
其中,string是要执行的JavaScript代码的字符串形式。
对于eval函数,有个大佬讲得比较详细:
参考链接:https://blog.csdn.net/weixin_43804496/article/details/124529573