Vue双向数据绑定原理
<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>
<input placeholder="请输入用户名" id ="username" type="text">
显示值:<p id="uName"></p>
</head>
<body>
<script>
let obj ={}
debugger
Object.defineProperty(obj,'username',{
// 取值
get:function(){
console.log('取值');
},
set:function(val){
console.log('设置值');
document.getElementById("uName").innerText = val
}
})
document.getElementById("username").addEventListener("keyup",function(){
//event
obj.username = event.target.value
})
</script>
</body>