学习vue 2.x源码笔记
1、响应式原理:
核心:Object.defineProperty,用法如下:
var obj1 = {}; var initValue = 'hello'; Object.defineProperty(obj1,"newKey1",{ //writable:true, //value:123, //enumerable:true, configurable:true, get:function(){ return initValue; }, set:function(val){ console.log('set:',val); initValue = val; } }); obj1.newKey1; //->"hello" obj1.newKey1 = 'modified';//->set: modified //->"modified"