-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtodolist组件.html
48 lines (46 loc) · 1020 Bytes
/
todolist组件.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>todolise 组件</title>
<script type="text/javascript" src="./js/vue.js"></script>
</head>
<body>
<div id="app">
<todo-list></todo-list>
<todo-list></todo-list>
<todo-list></todo-list>
<todo-list></todo-list>
</div>
<script type="text/javascript">
Vue.component("todo-list",{
template: `<div>
<input type="text" v-model="todo" v-on:keydown.13="add"><button v-on:click="add">发布</button>
<ol>
<li v-for="(item,index) in todolist">{{item}}
<button v-on:click="remove(index)">×</button>
</li>
</ol>
</div>`,
data: function(){
return {
todo: "",
todolist: [],
}
},
methods: {
add: function(){
if(this.todo.trim()) this.todolist.unshift(this.todo.trim());
this.todo="";
},
remove: function(index){
this.todolist.splice(index,1);
}
}
})
var vm=new Vue({
el: "#app",
})
</script>
</body>
</html>