想问下vue
的数据驱动原理
当Observer
对象下的getter
获取到值的变更后,这个值是怎么传给Wathcer
对象的??看源码有些蒙不知道是咋回事?
Watcher.prototype.get = function get () {
pushTarget(this);
var value;
var vm = this.vm;
try {
value = this.getter.call(vm, vm);
} catch (e) {
if (this.user) {
handleError(e, vm, ("getter for watcher \"" + (this.expression) + "\""));
} else {
throw e
}
} finally {
// "touch" every property so they are all tracked as
// dependencies for deep watching
if (this.deep) {
traverse(value);
}
popTarget();
this.cleanupDeps();
}
return value
};
在执行更新时run方法中调用get方法获取值,get方法中返回getter方法返回的值。