1.动态赋值
<div
v-for="(item, index) in typeList"
:key="item.id"
>
<a-input
v-if="inputSecondaryVisible && curSecondaryInputIndex === index"
:ref="'input' + index"
type="text"
:value="inputSecondaryValue"
@change="handleSecondaryInputChange"
/>
<a-tag
v-else
@click="showSecondaryInput(index)"
>
<a-icon type="plus" /> 添 加
</a-tag>
</div>
2.取值
showSecondaryInput(index) {
this.curSecondaryInputIndex = index;
this.inputSecondaryVisible = true;
let inputRef = "secondaryInput" + index;//获取到当前input的ref
this.$nextTick(function () {
this.$refs[inputRef][0].focus();//通过ref对当前input获取焦点
});
},
因为refs是一个数组,所以一定得加上[0]才能获取当前的ref。