Vue雙向綁定原理

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Vue雙向綁定原理</title>
</head>
<body>

  <input>
  <p id="p"></p>

  <script>
    var obj = {}
    Object.defineProperty(obj, 'txt', {
      get: function () {
        return obj
      },
      set: function (newValue) {
        document.getElementById('p').innerHTML = newValue
      }
    })
    document.addEventListener('keyup', function (e) {
      obj.txt = e.target.value
    })
  </script>
  
</body>
</html>
複製代碼
相關文章
相關標籤/搜索