页面结构
<ul>
<li v-for="(item, index) in itemArr" :key="index">
<el-input v-model="item.content"></el-input>
</li>
</ul>
<button @click="deleteEle(index)">删除</button>
<button @click="addEle">+添加元素</button>
data初始化
data() {
return {
itemArr: [{
content: ''
}]
}
}
方法
// 点击添加
addEle() {
this.itemArr.push({
content: ''
})
},
// 删除一项
deleteEle(index) {
this.itemArr.splice(index, 1);
},