首页 > 其他 > 详细

vue双向数据绑定的简单实现

时间:2018-09-27 16:27:55      阅读:163      评论:0      收藏:0      [点我收藏+]

vue双向数据绑定的简单实现

参考教程:链接

<!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>Document</title>
</head>
<body>
    <div id="app">
     <input type="text" id="txt">
     <p id="show-txt"></p>
    </div>
    <script>
     var obj = {}
     Object.defineProperty(obj, txt, {
      get: function () {
       return obj
      },
      set: function (newValue) {
       document.getElementById(txt).value = newValue
       document.getElementById(show-txt).innerHTML = newValue
      }
     })
     document.addEventListener(keyup, function (e) {
      obj.txt = e.target.value
     })
    </script>
   </body>
</html>

 

vue双向数据绑定的简单实现

原文:https://www.cnblogs.com/zzxuan/p/9713690.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!