-
Notifications
You must be signed in to change notification settings - Fork 475
/
Copy path04.MutationObserver.html
69 lines (60 loc) · 1.54 KB
/
04.MutationObserver.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
68
69
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<script src="vue.js"></script>
<style>
pre {
margin: 0;
padding: 0.3em;
border: 1px dashed #2f6fab;
background-color: #f9f9f9;
color: black;
line-height: 1em;
font-family: verdana, helvetica, sans-serif;
}
body{
margin-top: 100px;
}
</style>
</head>
<body>
<div id="app">
<h1>vm</h1>
<input type='text' v-model='a'> {{a}}
</div>
<div id='mo'></div>
<script>
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
// 选择目标节点
var target = document.querySelector('#app');
// 创建观察者对象
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var d = new Date();
console.log('有变化了:'+mutation.type+',时间:'+d.getTime());
});
});
// 配置观察选项:
var config = {
attributes: true,
childList: true,
characterData: true
}
// 传入目标节点和观察选项
observer.observe(target, config);
var vm = new Vue({
data: {
a: 1
},
el: '#app',
})
setTimeout(function() {
document.getElementById('app').innerHTML = '台湾小凡喜欢 vue.js';
}, 2000);
</script>
</body>
</html>