Просмотр исходного кода

fix(core): fix merged twice bug when passing extended constructor to mixins (#9199)

fix #9198
hikerpig 7 лет назад
Родитель
Сommit
537161779e
2 измененных файлов с 30 добавлено и 2 удалено
  1. 2 2
      src/core/util/options.js
  2. 28 0
      test/unit/features/options/mixins.spec.js

+ 2 - 2
src/core/util/options.js

@@ -382,13 +382,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.

+ 28 - 0
test/unit/features/options/mixins.spec.js

@@ -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)
+  })
 })