v-model数据劫持 网上直接说 v-model原理
作者:互联网
<!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" id="input">
<br>
<p></p>
<script> let obj = {} let inp = document.getElementById('input'); let p = document.getElementsByTagName('p')[0]; Object.defineProperty(obj,'name',{ get(){ console.log('取'); }, set(val){ inp.innerText = val; } })
inp.addEventListener('keyup',function(e){ p.innerText = e.target.value; }) </script> </body> </html>
<script> let obj = {} let inp = document.getElementById('input'); let p = document.getElementsByTagName('p')[0]; Object.defineProperty(obj,'name',{ get(){ console.log('取'); }, set(val){ inp.innerText = val; } })
inp.addEventListener('keyup',function(e){ p.innerText = e.target.value; }) </script> </body> </html>
标签:劫持,obj,val,innerText,inp,let,原理,model,document 来源: https://www.cnblogs.com/coderwhytop/p/15498005.html