fix(runtime-core): properly call lifecycle hooks in chained mixins & extends (#1974)
fix #1973
This commit is contained in:
@@ -614,11 +614,11 @@ function callSyncHook(
|
||||
globalMixins: ComponentOptions[]
|
||||
) {
|
||||
callHookFromMixins(name, globalMixins, ctx)
|
||||
const baseHook = options.extends && options.extends[name]
|
||||
if (baseHook) {
|
||||
baseHook.call(ctx)
|
||||
|
||||
const { extends: base, mixins } = options
|
||||
if (base) {
|
||||
callHookFromExtends(name, base, ctx)
|
||||
}
|
||||
const mixins = options.mixins
|
||||
if (mixins) {
|
||||
callHookFromMixins(name, mixins, ctx)
|
||||
}
|
||||
@@ -628,12 +628,30 @@ function callSyncHook(
|
||||
}
|
||||
}
|
||||
|
||||
function callHookFromExtends(
|
||||
name: 'beforeCreate' | 'created',
|
||||
base: ComponentOptions,
|
||||
ctx: ComponentPublicInstance
|
||||
) {
|
||||
if (base.extends) {
|
||||
callHookFromExtends(name, base.extends, ctx)
|
||||
}
|
||||
const baseHook = base[name]
|
||||
if (baseHook) {
|
||||
baseHook.call(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
function callHookFromMixins(
|
||||
name: 'beforeCreate' | 'created',
|
||||
mixins: ComponentOptions[],
|
||||
ctx: ComponentPublicInstance
|
||||
) {
|
||||
for (let i = 0; i < mixins.length; i++) {
|
||||
const chainedMixins = mixins[i].mixins
|
||||
if (chainedMixins) {
|
||||
callHookFromMixins(name, chainedMixins, ctx)
|
||||
}
|
||||
const fn = mixins[i][name]
|
||||
if (fn) {
|
||||
fn.call(ctx)
|
||||
|
||||
Reference in New Issue
Block a user