-
Notifications
You must be signed in to change notification settings - Fork 65
/
数据绑定的容器更新.html
49 lines (44 loc) · 1.19 KB
/
数据绑定的容器更新.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<input type="text" v-model="content" />
<input type="text" v-model="title" />
<input type="text" v-model="title" />
<h4 v-bind="content"></h4>
</body>
<script>
function View() {
let proxy = new Proxy({}, {
set(obj, property, value) {
console.log(obj, property, value);
document.querySelectorAll(`[v-model="${property}"]`)
.forEach((item) => {
item.value = value;
});
document
.querySelectorAll(`[v-bind="${property}"]`)
.forEach((item) => {
item.innerHTML = value;
});
},
get(obj, property) { },
});
this.init = function () {
const els = document.querySelectorAll(`[v-model]`);
els.forEach((item) => {
item.addEventListener('keyup', function () {
//触发proxy的set
proxy[this.getAttribute('v-model')] = this.value;
});
});
};
}
new View().init();
</script>
</html>