<template>
<div v-for="(item,index) in listData" :key="index">
<Input v-model="item.inputValue" type="text" placeholder="请输入内容" ref="reflistData"
:disabled="item.isEdit" @on-blur="BlurFn(item,index)"/>
<Button @click="EditFn(item,index)">编辑</Button>
</div>
</template>
<script>
export default {
name: '',
data() {
return {
listData:[
{
name:'测试1',
inputValue:'',
isEdit:true
},
{
name:'测试1',
inputValue:'',
isEdit:true
}
]
}
}
methods: {
EditFn(item,index){
let itemObj=item
itemObj.isEdit=false
console.log( this.$refs.reflistData)
this.$set(this.listData,index,itemObj)
this.$nextTick(()=>{
this.$refs.reflistData[index].focus()
})
},
BlurFn(item,index){
let itemObj=item
itemObj.isEdit=true
this.$set(this.listData,index,itemObj)
this.$nextTick(()=>{
this.$refs.reflistData[index].blur()
})
}
}
}
</script>
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/90cb8d44a3b74466a7fd5fc79f2fa078.png)