Skip to content

createWatcher

javascript
function createWatcher(
  vm: Component,
  expOrFn: string | (() => any),
  handler: any,
  options?: Object
) {
  // handler 是对象
  if (isPlainObject(handler)) {
    // 配置项
    options = handler
    // 真正的 handler
    handler = handler.handler
  }
  // handler 是字符串,直接去 vm 中取这个 method
  if (typeof handler === 'string') {
    handler = vm[handler]
  }
  // 通过 vm.$watch 生成 user watcher
  return vm.$watch(expOrFn, handler, options)
}