ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

proxy

2022-05-04 15:33:36  阅读:40  来源: 互联网

标签:set target show value proxy key input


<!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>proxy第三遍</title>
  </head>
  <body>
    <input type="text" id="input" />
    <p id="show"></p>
    <script>
      let obj = {};
      const input = document.getElementById('input');
      const show = document.getElementById('show');
      let newObj = new Proxy(obj, {
        set(target, key, value) {
          // vue3中此段代码采用发布订阅模式,传递到订阅者调用模板解析,diff对比改变,更新;
          if (key === 'text') {
            input.value = value;
            show.innerHTML = value;
          }

          return Reflect.set(target, key, value);
        },
        get(target, key) {
          return Reflect.get(target, key);
        }
      });
      input.addEventListener('keyup', function (e) {
        newObj.text = e.target.value;
      });
    </script>
  </body>
</html>

 

标签:set,target,show,value,proxy,key,input
来源: https://www.cnblogs.com/pengxiangchong/p/16221251.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有