mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
perf(nuxt): unsubscribe from asyncData
watch when unmounted (#26821)
This commit is contained in:
parent
6d7a558c69
commit
468ebbdf0b
@ -375,7 +375,9 @@ export function useAsyncData<
|
|||||||
const hasScope = getCurrentScope()
|
const hasScope = getCurrentScope()
|
||||||
if (options.watch) {
|
if (options.watch) {
|
||||||
const unsub = watch(options.watch, () => asyncData.refresh())
|
const unsub = watch(options.watch, () => asyncData.refresh())
|
||||||
if (hasScope) {
|
if (instance) {
|
||||||
|
onUnmounted(unsub)
|
||||||
|
} else if (hasScope) {
|
||||||
onScopeDispose(unsub)
|
onScopeDispose(unsub)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -384,7 +386,9 @@ export function useAsyncData<
|
|||||||
await asyncData.refresh()
|
await asyncData.refresh()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (hasScope) {
|
if (instance) {
|
||||||
|
onUnmounted(off)
|
||||||
|
} else if (hasScope) {
|
||||||
onScopeDispose(off)
|
onScopeDispose(off)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user