目录介绍 Object.defineProperty Proxy介绍 数据绑定是一种把用户界面元素(控件)的属性绑定到特定对象上面并使其同步的机制,使开发人员免于编写同步视图模型和视图的逻辑。观察者模
顺晟科技
2022-09-23 11:07:53
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Proxy vue 双向绑定</title>
</head>
<body>
<div >
<h3 ></h3>
<input type="text" />
</div>
</body>
</html>
<script>
const papagraph = document.getElementById('papagraph');
const input = document.getElementById('input');
const data = {
text: 'hello'
}
const handler = {
set: function(target, prop, value) {
if (prop === 'text') {
target[prop] = value
papagraph.innerHTML = value
return true;
} else {
return false;
}
}
}
const myTest = new Proxy(data, handler);
input.addEventListener(
'input',
e => {
myTest.text = e.target.value;
},
false
)
</script>
19
2022-10
23
2022-09
13
2022-09
13
2022-09
13
2022-09
13
2022-09