-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
55 lines (47 loc) · 1.35 KB
/
index.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
<!--
* @Author: panghu 760695955@qq.com
* @Date: 2023-08-03 17:10:52
* @LastEditors: 阿喜
* @LastEditTime: 2023-08-04 23:00:24
* @FilePath: \vue-mini\index.html
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script>
class targetProxy {
constructor(obj) {
this.target = obj
this.proxy = new Proxy(this.target, {
get: (target, key) => {
console.log(Reflect.get(target, key), 'get')
return Reflect.get(target, key)
},
set: (target, key, value) => {
if (key === 'name') {
document.querySelectorAll('#app')[0].innerHTML = value
}
console.log(Reflect.set(target, key, value), 'set')
return Reflect.set(target, key, value)
}
})
}
}
const obj = new targetProxy({
name: 'tom',
age: 18
})
document.querySelectorAll('#app')[0].innerHTML = obj.proxy.name
setTimeout(() => {
obj.proxy.name = 'panghu'
}, 3000)
</script>
</body>
</html>