<div id="app">
<input type="text" v-model='inputVal'>
<button @click='handleBtnClick'>提交</button>
<ul>
<Todo-item v-bind:content="item"
v-bind:index="index"
v-for="(item,index) in list"
@delete='handleItemDelete'>
</Todo-item>
</ul>
</div>
var TodoItem = {
props:['content','index'],
template:"<li @click='handleClick'>{{content}}</li>",
methods:{
handleClick:function(){
console.log(this.index)
this.$emit("delete",this.index)
}
}
}
var app = new Vue({
el:"#app",
components:{
TodoItem:TodoItem
},
data:{
inputVal:'',
list: []
},
methods:{
handleBtnClick: function(){
this.list.push(this.inputVal);
this.inputVal = "";
},
handleItemDelete:function(index){
this.list.splice(index,1)
}
}
})