按键添加文本框

发布时间 2023-12-27 10:02:38作者: 不洗澡超酷
<template>
<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>