初学Vue练手的简易todolist
此简易Demo就不写样式了,主要是熟悉Vue的指令功能:添加、删除待办事项<!DOCTYPE html><html><head lang="en">&a
·
此简易Demo就不写样式了,主要是熟悉Vue的指令
功能:添加、删除待办事项
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>todolist</title>
<script src="vue.js"></script>
</head>
<body>
<div id="root">
<h2>简易todolistDemo</h2>
<input type="text" v-model="inputValue"/>
<button @click="handleSubmit">提交</button>
<p>待办事项:</p>
<ul>
<todo-item v-for="(item,index) in list"
:key="index"
:content="item"
:index="index"
@delete="handleDelete">
</todo-item>
</ul>
</div>
<script>
Vue.component('todo-item',{
props:['content','index'],
template:'<li @click="handleClick">{{content}}</li>',
methods:{
handleClick:function(){
this.$emit('delete',this.index);
}
}
});
new Vue({
el:"#root",
data:{
inputValue:'',
list:[]
},
methods:{
handleSubmit:function(){
this.list.push(this.inputValue);
this.inputValue = '';
},
handleDelete:function(index){
this.list.splice(index,1);
}
}
});
</script>
</body>
</html>
更多推荐
已为社区贡献2条内容
所有评论(0)