Skip to content

Commit 5371617

Browse files
hikerpigyyx990803
authored andcommitted
fix(core): fix merged twice bug when passing extended constructor to mixins (#9199)
fix #9198
1 parent c50bbde commit 5371617

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
@@ -382,13 +382,13 @@ export function mergeOptions (
382382
}
383383

384384
if (typeof child === 'function') {
385-
child = child.options
385+
child = child.extendOptions
386386
}
387387

388388
normalizeProps(child, vm)
389389
normalizeInject(child, vm)
390390
normalizeDirectives(child)
391-
391+
392392
// Apply extends and mixins on the child options,
393393
// but only if it is a raw options object that isn't
394394
// 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)