forked from 471314748/xiaotexiao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01v-model和watch监听器.html
65 lines (62 loc) · 1.31 KB
/
01v-model和watch监听器.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>监听器watch</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
{{ message }}
<br />
<input v-model="message">
<br />
<input v-model="a">
<br />
<input v-model="obj.age">
<br />
<input v-model="obj.name">
<br />
<input v-model="bh">
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
a:1,
obj:{
name:'gr',
age:18
},
bh:''
},
methods: {
// details: function () {
// return this.site + " - 学的不仅是技术,更是梦想!";
// }
},
watch: {
//普通的watch监听
a(val, oldVal){
console.log("a: "+val);
this.bh=+val+(+this.obj.age)
},
//深度监听,可监听到对象、数组的变化
obj:{
handler(val){
console.log("变化前后的值: "+val.age, '---');
},
deep:true, //true 深度监听
immediate: true //声明后立刻调用
}
// 无法监听
// obj(val, oldVal){
// console.log(val,oldVal);
// }
},
})
</script>
</html>