From 743edacdb6fa0bb711e860b68373274f50c8baa5 Mon Sep 17 00:00:00 2001 From: hikerpig <102706325@163.com> Date: Fri, 11 Jan 2019 05:10:54 +0800 Subject: [PATCH] fix(core): fix merged twice bug when passing extended constructor to mixins (#9199) fix #9198 --- src/core/util/options.js | 4 ++-- test/unit/features/options/mixins.spec.js | 28 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/core/util/options.js b/src/core/util/options.js index fc7826dc01d..333d08ab755 100644 --- a/src/core/util/options.js +++ b/src/core/util/options.js @@ -376,13 +376,13 @@ export function mergeOptions ( } if (typeof child === 'function') { - child = child.options + child = child.extendOptions } normalizeProps(child, vm) normalizeInject(child, vm) normalizeDirectives(child) - + // Apply extends and mixins on the child options, // but only if it is a raw options object that isn't // the result of another mergeOptions call. diff --git a/test/unit/features/options/mixins.spec.js b/test/unit/features/options/mixins.spec.js index 8385edfe03c..65c4e6055ff 100644 --- a/test/unit/features/options/mixins.spec.js +++ b/test/unit/features/options/mixins.spec.js @@ -109,4 +109,32 @@ describe('Options mixins', () => { expect(vm.b).toBeDefined() expect(vm.$options.directives.c).toBeDefined() }) + + it('should not mix global mixined lifecycle hook twice', () => { + const spy = jasmine.createSpy('global mixed in lifecycle hook') + Vue.mixin({ + created() { + spy() + } + }) + + const mixin1 = Vue.extend({ + methods: { + a() {} + } + }) + + const mixin2 = Vue.extend({ + mixins: [mixin1], + }) + + const Child = Vue.extend({ + mixins: [mixin2], + }) + + const vm = new Child() + + expect(typeof vm.$options.methods.a).toBe('function') + expect(spy.calls.count()).toBe(1) + }) })