-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest5.html
50 lines (49 loc) · 1.19 KB
/
test5.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>test5</title>
</head>
<body>
<script src="./js/observer.js"></script>
<script src="./js/watcher.js"></script>
<script src="./js/compile.js"></script>
<script>
/* eslint-disable no-new */
/* eslint-disable no-undef */
function mvue(options) {
this.$options = options
this.$data = options.data
this.$el = document.querySelector(options.el)
// 数据代理
Object.keys(this.$data).forEach(key => {
this.proxyData(key)
})
this.init()
}
mvue.prototype.init = function() {
observer(this.$data)
new Compile(this)
}
mvue.prototype.proxyData = function(key) {
Object.defineProperty(this, key, {
get: function() {
return this.$data[key]
},
set: function(value) {
this.$data[key] = value
}
})
}
</script>
<div id="app">{{ word }}</div>
<script>
const vm = new mvue({
el: '#app',
data: {
word: 'hello world, hello everyone!'
}
})
</script>
</body>
</html>