-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path8_watch.html
67 lines (59 loc) · 1.21 KB
/
8_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
66
67
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
#box{
width:100px;
height: 100px;
background-color: red;
}
#box.hide{
display: none;
}
</style>
</head>
<body>
<div id="app">
<!-- <input v-model="val"/> -->
<!-- {{Arr}} -->
<input type="checkbox" v-for="(val,key) in arr" v-model="val.checked"/>
</div>
<script src="vue.js" charset="utf-8"></script>
<script type="text/javascript">
/*
状态
传递
语法
watch:
当某个指定数据发生变化的时候,那么会进watch,如果要深度监听
被监听的数据:{
handler:function(val,oldVal){
},
deep:true
}
*/
let v = new Vue({
el:'#app',
data:{
arr:[{checked:false,id:0},{checked:false,id:1},{checked:false,id:2}]
},
// computed:{
// Arr:function(){
// localStorage.setItem('arr1',JSON.stringify(this.arr));
// //return JSON.stringify(this.arr);
// }
// }
watch:{
arr:{
handler:function(val,oldVal){
localStorage.setItem('arr1',JSON.stringify(this.arr));
},
deep: true
}
}
});
</script>
</body>
</html>