-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.vue实例.html
41 lines (41 loc) · 1 KB
/
1.vue实例.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue实例</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<body>
<div id="app">
{{obj.objMessage}}<input type="text" v-model="obj.objMessage"/>
<br/>
{{message}}<input type="text" v-model="message" />
</div>
</body>
<script>
var obj = {
objMessage:'我不会响应'
}
//阻止该对象的响应
Object.freeze(obj);
var vm = new Vue({
el:'#app',
data:{
obj,
message:'我会响应'
},
//不要在实例属性上使用箭头函数,箭头函数中没有this,会往上找
created: ()=>{
//undefined
console.log(this.message)
}
});
//实例属性的使用
console.log(vm.$data.obj == obj)
console.log(vm.$el == document.getElementById('app'))
vm.$watch('message',(newValue,oldValue)=>{
console.log(newValue,oldValue);
})
</script>
</html>