fix(watch): should trigger watcher callback on triggerRef when watching ref source

fix #1736
This commit is contained in:
Evan You
2020-07-30 18:29:38 -04:00
parent 09702e95b9
commit fce2689ff1
2 changed files with 29 additions and 4 deletions

View File

@@ -159,8 +159,9 @@ function doWatch(
}
let getter: () => any
if (isRef(source)) {
getter = () => source.value
const isRefSource = isRef(source)
if (isRefSource) {
getter = () => (source as Ref).value
} else if (isReactive(source)) {
getter = () => source
deep = true
@@ -239,7 +240,7 @@ function doWatch(
if (cb) {
// watch(source, cb)
const newValue = runner()
if (deep || hasChanged(newValue, oldValue)) {
if (deep || isRefSource || hasChanged(newValue, oldValue)) {
// cleanup before running cb again
if (cleanup) {
cleanup()