从源码中学Vue(五 ) 解析「观察者」Watcher做了什么?( 二 )

this.value = http://www.veick.cn/news/this.lazy? undefined : this.get()

那么在什么情况下会调用get方法呢,通过我前面的文章Vue生命周期详解 中知道,在mounted之前,会实例化一个Watcher

从源码中学Vue(五 ) 解析「观察者」Watcher做了什么?

可以看出来我们在实例化Watcher的时候,第4个参数我们没有传入lazy值,所以这个时候回过头看

this.value = http://www.veick.cn/news/this.lazy? undefined : this.get()

this.get方法会被调用。

再来看下get方法的源码

它调用了this.getter方法,而

从源码中学Vue(五 ) 解析「观察者」Watcher做了什么?

这个this.getter方法,实际就是我们传入的第二个参数expOrFn

推荐阅读