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>
上一篇:java中讲讲PrintStream的用法,举例?


下一篇:条件变量与互斥量(2)