<template>标签:index,onDelete,items,文本框,添加,按键 From: https://www.cnblogs.com/yangkaiwen/p/17929874.html
<div>
<div v-for="(item,i) of items" :key="i">
<input type="text" v-model="items[i]">
<button @click="onDelete(i)">删除</button>
</div>
<button @click="onAdd">添加</button>
</div>
</template>
<script>
export default {
data() {
return {
items: []
}
},
methods: {
onAdd() {
this.items.push('')
},
onDelete(index) {
this.items.splice(index, 1);
}
}
}
</script>