vue之双向绑定

上一博客说了MVVM,这一章就讲讲双向绑定

双向绑定按照Vue官方文档说的意思是实现了

Object.defineProperty(),正因为ie8及以下不支持这个方法所以Vue完全无法在ie8上运行


  <input type="text" id="txt" />
  
   <script>
    let obj={};
    let temp="";
   const txt = document.getElementById('txt')
   txt.οninput=function(){
        console.log(this.value);
        obj.name=this.value
   }

   Object.defineProperty(obj,'name',{
       set:function(newValue){
            console.log(newValue)
            temp=newValue;
            txt.value = newValue
       },
       get:function(){
           return  temp;
       }
   });
    
    </script> 

发布了52 篇原创文章 · 获赞 2 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/liz9411/article/details/103985145