vue 数据监听原理
1 Vue.prototype.listenDatas = function(){ 2 for(var attr in this.$data){ 3 this.listenData(this,attr,this.$data); 4 if(Array.isArray(this.$data[attr])){ 5 this.$data[attr].__proto__ = this.newArrMethods; 6 for(var i=0;i<this.$data[attr].length;i++){ 7 for(var attr_child in this.$data[attr][i]){ 8 this.listenData(this.$data[attr][i],attr_child,this.cloneObj(this.$data[attr][i])); 9 } 10 } 11 } 12 } 13 }; 14 Vue.prototype.listenData = function(obj,attr,data){ 15 var This = this; 16 Object.defineProperty(obj, attr, { 17 configurable : true, 18 enumerable : true, 19 get : function(){ 20 return data[attr]; 21 }, 22 set : function(val){ 23 data[attr] = val; 24 This.render(This.$temp); 25 } 26 }); 27 };