Skip to content

Commit 9024171

Browse files
hikerpigaJean
authored andcommitted
fix(core): fix merged twice bug when passing extended constructor to mixins (vuejs#9199)
fix vuejs#9198
1 parent 573996a commit 9024171

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/core/util/options.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ export function mergeOptions (
376376
}
377377

378378
if (typeof child === 'function') {
379-
child = child.options
379+
child = child.extendOptions
380380
}
381381

382382
normalizeProps(child, vm)
383383
normalizeInject(child, vm)
384384
normalizeDirectives(child)
385-
385+
386386
// Apply extends and mixins on the child options,
387387
// but only if it is a raw options object that isn't
388388
// the result of another mergeOptions call.

test/unit/features/options/mixins.spec.js

+28
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,32 @@ describe('Options mixins', () => {
109109
expect(vm.b).toBeDefined()
110110
expect(vm.$options.directives.c).toBeDefined()
111111
})
112+
113+
it('should not mix global mixined lifecycle hook twice', () => {
114+
const spy = jasmine.createSpy('global mixed in lifecycle hook')
115+
Vue.mixin({
116+
created() {
117+
spy()
118+
}
119+
})
120+
121+
const mixin1 = Vue.extend({
122+
methods: {
123+
a() {}
124+
}
125+
})
126+
127+
const mixin2 = Vue.extend({
128+
mixins: [mixin1],
129+
})
130+
131+
const Child = Vue.extend({
132+
mixins: [mixin2],
133+
})
134+
135+
const vm = new Child()
136+
137+
expect(typeof vm.$options.methods.a).toBe('function')
138+
expect(spy.calls.count()).toBe(1)
139+
})
112140
})

0 commit comments

Comments
 (0)