<body>
<script src='https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js'></script>
<div id='myApp'>
<input type="text" v-model.trim="add" @keyup.enter='hh'>
<ol>
<li v-for="(item,index) in arr">
<b>{{item}}</b>
<button @click='remove(index)'>删除</button>
</li>
</ol>
</div>
<script>
new Vue({
el: '#myApp',
data: {
add: '',
arr: []
},
methods: {
hh(e) {
if (e.target.value.trim() != '') {
this.arr.push(this.add)
this.add = ''
}
},
remove(i) {
this.arr.splice(i, 1)
}
}
})
</script>
</body>