-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.js
57 lines (49 loc) · 1.16 KB
/
vue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 实现初始化设置和数据监测
function Vue(options){
console.log('Vue start!')
// console.log(this)
// 初始的this--一个空对象;
// 取到数据
this.$options=options||{
data:'hello VueJs!'
}
// 添加默认设置
var data=this._data=this.$options.data;
var me=this;
// 数据代理,可以在外部修改数据
// for(let key of Object.keys(data)){
// me._proxyData(key);
// }
Object.keys(data).forEach(function(key){
me._proxyData(key);
})
observer(data,this);
// 数据观测,set方法定义。
// get方法在下面用到
// 编译模板
this.$compile=new Compile(options.el||document.body,this);
// 传到这个里面的this--挂载了以上的全部方法;
// console.log(this)
}
Vue.prototype={
_proxyData:function(key,setter,getter){
var me=this;
console.log(key)
Object.defineProperty(me,key,{
configurable:false,
enumerable:true,
get:function proxyGet(){
return me._data[key];
},
set:function proxySet(newV){
// if(me._data[key]==newV){
// console.log('一样')
// return;
// }
me._data[key]=newV;
// console.log('changeok');
console.log(me._data[key])
}
});
},
}