Skip to content

Commit ae6fd71

Browse files
hikerpighefeng
authored and
hefeng
committed
fix(core): fix merged twice bug when passing extended constructor to mixins (vuejs#9199)
fix vuejs#9198
1 parent 7a5cece commit ae6fd71

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

src/core/util/options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ export function mergeOptions (
395395
}
396396

397397
if (typeof child === 'function') {
398-
child = child.options
398+
child = child.extendOptions
399399
}
400400

401401
normalizeProps(child, vm)

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

+17-21
Original file line numberDiff line numberDiff line change
@@ -110,35 +110,31 @@ describe('Options mixins', () => {
110110
expect(vm.$options.directives.c).toBeDefined()
111111
})
112112

113-
it('should accept further extended constructors as mixins', () => {
114-
const spy1 = jasmine.createSpy('mixinA')
115-
const spy2 = jasmine.createSpy('mixinB')
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+
})
116120

117-
const mixinA = Vue.extend({
118-
created: spy1,
119-
directives: {
120-
c: {}
121-
},
121+
const mixin1 = Vue.extend({
122122
methods: {
123-
a: function () {}
123+
a() {}
124124
}
125125
})
126126

127-
const mixinB = mixinA.extend({
128-
created: spy2
127+
const mixin2 = Vue.extend({
128+
mixins: [mixin1],
129129
})
130130

131-
const vm = new Vue({
132-
mixins: [mixinB],
133-
methods: {
134-
b: function () {}
135-
}
131+
const Child = Vue.extend({
132+
mixins: [mixin2],
136133
})
137134

138-
expect(spy1).toHaveBeenCalledTimes(1)
139-
expect(spy2).toHaveBeenCalledTimes(1)
140-
expect(vm.a).toBeDefined()
141-
expect(vm.b).toBeDefined()
142-
expect(vm.$options.directives.c).toBeDefined()
135+
const vm = new Child()
136+
137+
expect(typeof vm.$options.methods.a).toBe('function')
138+
expect(spy.calls.count()).toBe(1)
143139
})
144140
})

0 commit comments

Comments
 (0)