-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMVVM.html
56 lines (51 loc) · 1.58 KB
/
MVVM.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
<!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>双向绑定</title>
</head>
<body>
<script src="./dist/js/main.bundle.js"></script>
<div id="app">
<input type="text" v-model="firstName">
<input type="text" v-model="htmlStr">
<p v-text="firstName"></p>
<p>
{{firstName}}{{array.length}}
{{{htmlStr}}}
<span v-text="child.lastName"></span>
</p>
<p v-html="htmlStr"></p>
<button v-on:click="clickBtn">改变数组内容</button>
<button v-on:click="addItem(firstName)">数组增加长度</button>
<ul>
<li v-for="item in array" class="list-item">{{item}}</li>
</ul>
<p>{{array.length}}</p>
</div>
<script>
let vm = new MVVM({
el: '#app',
data: {
firstName: "hello ",
htmlStr: '<span style="color: #f00;">我是v-html指令的结果</span><span>sdf</spam>',
child: {
lastName: ' World !'
},
array: ["sdf","sdfd"]
},
methods: {
clickBtn: function (e) {
this.array[0] = "dfsdf";
},
addItem: function (value) {
this.array.push(value);
console.log(this.array);
}
}
});
</script>
</body>
</html>