-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_数据劫持-数据绑定.html
44 lines (42 loc) · 1 KB
/
06_数据劫持-数据绑定.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>06_数据劫持-数据绑定</title>
<!--
1. 数据绑定
* 初始化显示: 页面(表达式/指令)能从data读取数据显示 (编译/解析)
* 更新显示: 更新data中的属性数据==>页面更新
-->
</head>
<body>
<div id="test">
<p>{{name}}</p>
<p v-text="name"></p>
<p>{{wife.name}}</p>
<button v-on:click="update">更新</button>
</div>
<script type="text/javascript" src="./js/mvvm/compile.js"></script>
<script type="text/javascript" src="./js/mvvm/observer.js"></script>
<script type="text/javascript" src="./js/mvvm/watcher.js"></script>
<script type="text/javascript" src="./js/mvvm/mvvm.js"></script>
<script type="text/javascript">
const vm = new MVVM({
el: '#test',
data: {
name: 'sadamu',
wife: {
name: 'DY',
age: 22
}
},
methods: {
update () {
this.name = 'SADAMU'
this.wife.name = 'BB'
}
}
})
</script>
</body>
</html>