Skip to content

Commit 542a381

Browse files
yyx990803hefeng
authored and
hefeng
committed
fix(core): dedupe lifecycle hooks during options merge
The fix landed in vuejs#9199 causes further extended constructors used as mixins to drop options from its inheritance chain, so a different fix is needed.
1 parent 7b7b34f commit 542a381

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
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.extendOptions
398+
child = child.options
399399
}
400400

401401
normalizeProps(child, vm)

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

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

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

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

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

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

135-
const vm = new Child()
136-
137-
expect(typeof vm.$options.methods.a).toBe('function')
138-
expect(spy.calls.count()).toBe(1)
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()
139143
})
140144
})

0 commit comments

Comments
 (0)