-
Notifications
You must be signed in to change notification settings - Fork 0
/
05_compenent.html
88 lines (76 loc) · 1.95 KB
/
05_compenent.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="js/vue.js"></script>
</head>
<body>
<template id="tplTodoAdd">
<div>
<input type="text"><button>添加</button>
</div>
</template>
<script>
var todoAdd={
template:"#tplTodoAdd"
}
</script>
<template id="tplTodoItem">
<li>{{i+1}}-{{task}}</li>
</template>
<script>
var todoItem={
template:"#tplTodoItem",
props:["task","i"] //对外:父组件可绑定数据 对内data{task:xxx,i:x}
}
</script>
<template id="tplTodoList">
<ul>
<todo-item v-for="(task,i) of tasks" :task="task" :i="i"></todo-item>
</ul>
</template>
<script>
var todoList={
template:"#tplTodoList",
props:["tasks"],
components:{
todoItem
}
}
</script>
<template id="tplTodo">
<div>
<h1>待办事项列表</h1>
<todo-add></todo-add>
<todo-list :tasks="tasks"></todo-list>
</div>
</template>
<script>
Vue.component("todo",{
template:"#tplTodo",
data:function(){
return {
tasks:["吃饭","睡觉","打豆豆","打日天"]
}
},
components:{
todoAdd,
todoList
}
})
</script>
<div id="app">
<todo></todo>
</div>
<script>
var vm=new Vue({
el:"#app",
data:{
}
})
</script>
</body>
</html>