<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue入门</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
<div id="root">
<div>
<input type="text" v-model="inputValue">
<button @click="one">保存</button>
</div>
<ul>
<todo-item v-for="(i,index) of list" :key="index" :content="i" :index="index" @delete="deleteLi"></todo-item>
</ul>
</div>
</body>
<script>
Vue.component('todo-item',{
props:['content','index'],
template: '<li @click="two" >{{content}}</li>',
methods:{
two:function(){
this.$emit('delete',this.index)
}
}
});
new Vue({
el:'#root',
data:{
inputValue:'',
list:[]
},
methods:{
one:function(){
this.list.push(this.inputValue);
this.inputValue= ''
},
deleteLi:function(index){
this.list.splice(index,1)
}
}
})
</script>
</html>