fix(reactivity): should not trigger watch on computed ref when value is unchanged

fix #2231
This commit is contained in:
Evan You
2020-10-06 18:16:20 -04:00
parent a66e53a24f
commit 390589ec6d
3 changed files with 28 additions and 9 deletions

View File

@@ -161,9 +161,10 @@ function doWatch(
}
let getter: () => any
const isRefSource = isRef(source)
if (isRefSource) {
let forceTrigger = false
if (isRef(source)) {
getter = () => (source as Ref).value
forceTrigger = !!(source as Ref)._shallow
} else if (isReactive(source)) {
getter = () => source
deep = true
@@ -242,7 +243,7 @@ function doWatch(
if (cb) {
// watch(source, cb)
const newValue = runner()
if (deep || isRefSource || hasChanged(newValue, oldValue)) {
if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
// cleanup before running cb again
if (cleanup) {
cleanup()