标签:lan roo mod doc 组件 key put doctype utf-8
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ToDoList功能开发</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<div>
<input v-model="inputValue">
<button @click="handleSubmint">提交</button>
<ul>
<!-- <li v-for="(item,index) of list":key="index">{{item}}</li> -->
<!-- @delete="handleDelete" -->
<todo-item v-for="(item,index) of list "
:key="index"
:content="item"
:index="index"
@delete="handleDelete"
></todo-item>
</ul>
</div>
</div>
<script>
// a全局组件
/*Vue.component(‘todo-item‘,{
template:‘<li>item</li>‘
})*/
// 局部组件
var TodoItem={
props:[‘content‘,‘index‘],
template:‘<li @click="handleClick">{{content}}</li>‘,
methods:{
handleClick:function(){
// 子组件的删除
this.$emit(‘delete‘,this.index)
// alert(index)
}
}
}
new Vue({
el:"#root",
components:{
‘todo-item‘:TodoItem
},
data:{
inputValue:‘‘,
list:[],
},
methods:{
handleSubmint:function () {
this.list.push(this.inputValue),
this.inputValue=‘‘;
},
handleDelete:function(index){
this.list.splice(index,1)
// alert(index)
}
}
})
</script>
</body>
</html>
标签:lan roo mod doc 组件 key put doctype utf-8
原文地址:https://www.cnblogs.com/yanit1729/p/9619671.html