<h1>v-model的原理</h1> <!-- 1.双向数据绑定 --> <input placeholder="请输入名字" id="username"/> <div>显示值:<p id="uName"></p></div> <script> let obj={} Object.defineProperty(obj,'username',{ // 取值 get:()=>{ console.log("取值"); }, set:(val)=>{ console.log(val,"设置值"); document.getElementById('uName').innerText=val } }) document.getElementById('username').addEventListener('keyup', ()=>{ console.log(event); // event obj.username= event.target.value }) </script>