MCPcopy Create free account
hub / github.com/ygs-code/vue / createWatcher

Function createWatcher

vue.js:5201–5219  ·  view source on GitHub ↗
(vm,  //vm对象
        expOrFn, // key 值 或者函数
        handler, // 函数 或者 对象 或者key
        options  // 参数
    )

Source from the content-addressed store, hash-verified

5199
5200 // 转义handler 并且为数据 创建 Watcher 观察者
5201 function createWatcher(vm, //vm对象
5202 expOrFn, // key 值 或者函数
5203 handler, // 函数 或者 对象 或者key
5204 options // 参数
5205 ) {
5206 if (isPlainObject(handler)) { //判断是否是对象
5207 options = handler;
5208 handler = handler.handler; //对象中的handler 一定是函数或者字符串
5209 }
5210 if (typeof handler === 'string') { //判断handler 是否是字符串 如果是 则是key
5211 handler = vm[handler]; //取值 vm 就是Vue 最外层 中的函数
5212 }
5213 //转义handler 并且为数据 创建 Watcher 观察者
5214 return vm.$watch(
5215 expOrFn,// key 值 或者函数
5216 handler, //函数
5217 options //参数
5218 )
5219 }
5220
5221 //数据绑定,$watch方法
5222 function stateMixin(Vue) {

Callers 2

initWatchFunction · 0.85
stateMixinFunction · 0.85

Calls 1

isPlainObjectFunction · 0.85

Tested by

no test coverage detected