Skip to content

Commit

Permalink
fix(core): fix merged twice bug when passing extended constructor to …
Browse files Browse the repository at this point in the history
…mixins (#9199)

fix #9198
  • Loading branch information
hikerpig authored and yyx990803 committed Jan 11, 2019
1 parent d21e931 commit 743edac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions test/unit/features/options/mixins.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit 743edac

Please sign in to comment.