fix(watch): this.$watch should support watching keypath

This commit is contained in:
Evan You
2021-04-07 16:19:04 -04:00
parent 0f2d8f3244
commit 870f2a7ba3
3 changed files with 49 additions and 13 deletions

View File

@@ -20,7 +20,12 @@ import {
isPromise
} from '@vue/shared'
import { computed } from './apiComputed'
import { watch, WatchOptions, WatchCallback } from './apiWatch'
import {
watch,
WatchOptions,
WatchCallback,
createPathGetter
} from './apiWatch'
import { provide, inject } from './apiInject'
import {
onBeforeMount,
@@ -939,17 +944,6 @@ function createWatcher(
}
}
function createPathGetter(ctx: any, path: string) {
const segments = path.split('.')
return () => {
let cur = ctx
for (let i = 0; i < segments.length && cur; i++) {
cur = cur[segments[i]]
}
return cur
}
}
export function resolveMergedOptions(
instance: ComponentInternalInstance
): ComponentOptions {