fix(compat): correctly merge lifecycle hooks when using Vue.extend (#3762)

fix #3761
This commit is contained in:
Stanislav Lashmanov
2021-05-13 00:13:44 +03:00
committed by GitHub
parent a56ab148fd
commit 2bfb8b574d
4 changed files with 79 additions and 44 deletions

View File

@@ -113,11 +113,15 @@ export const legacyOptionMergeStrats = {
watch: mergeObjectOptions
}
function toArray(target: any) {
return isArray(target) ? target : target ? [target] : []
}
function mergeHook(
to: Function[] | Function | undefined,
from: Function | Function[]
) {
return Array.from(new Set([...(isArray(to) ? to : to ? [to] : []), from]))
return Array.from(new Set([...toArray(to), ...toArray(from)]))
}
function mergeObjectOptions(to: Object | undefined, from: Object | undefined) {