-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTodoList 循环及双向绑定.html
62 lines (52 loc) · 1.52 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="root"></div>
</body>
<script>
// 1 通过li标签把list循环打印 v-for 循环打印(元素 of 列表)元素后也可以接下标打印index
// Vue.createApp({
// data() {
// return {
// list: ['hello', 'world', 'dell', 'lee']
// }
// },
// template: `
// <ul>
// <li v-for = "(item, index) of list">{{item}} {{index}}</li>
// </ul>
// `
// }).mount('#root')
// 2 双向绑定 v-model 将template 与 data 中设的事件绑定
Vue.createApp({
data() {
return {
inputValue: '',
list: []
}
},
methods: {
handlaAppItem() {
this.list.push(this.inputValue);
this.inputValue = '';
}
},
template: `
<div>
<input v-model = "inputValue"/>
<button v-on:click = "handlaAppItem">增加</button>
<ul>
<li v-for = "(item, index) of list">{{item}} {{index}}</li>
</ul>
</div>
`
}).mount('#root')
</script>
</html>