diff --git a/src/core/util/options.js b/src/core/util/options.js index e3b1b718f54..53f96830165 100644 --- a/src/core/util/options.js +++ b/src/core/util/options.js @@ -1,6 +1,5 @@ /* @flow */ -import Vue from '../instance/index' import config from '../config' import { warn } from './debug' import { set } from '../observer/index' @@ -275,21 +274,20 @@ export function mergeOptions ( if (process.env.NODE_ENV !== 'production') { checkComponents(child) } + + if (typeof child === 'function') { + child = child.options + } + normalizeProps(child) normalizeDirectives(child) const extendsFrom = child.extends if (extendsFrom) { - parent = typeof extendsFrom === 'function' - ? mergeOptions(parent, extendsFrom.options, vm) - : mergeOptions(parent, extendsFrom, vm) + parent = mergeOptions(parent, extendsFrom, vm) } if (child.mixins) { for (let i = 0, l = child.mixins.length; i < l; i++) { - let mixin = child.mixins[i] - if (mixin.prototype instanceof Vue) { - mixin = mixin.options - } - parent = mergeOptions(parent, mixin, vm) + parent = mergeOptions(parent, child.mixins[i], vm) } } const options = {} diff --git a/test/unit/features/global-api/mixin.spec.js b/test/unit/features/global-api/mixin.spec.js index e0ae7ce2439..f452dbed8d2 100644 --- a/test/unit/features/global-api/mixin.spec.js +++ b/test/unit/features/global-api/mixin.spec.js @@ -124,4 +124,21 @@ describe('Global API: mixin', () => { expect(Test.options.computed.$style()).toBe(123) expect(Test.options.beforeCreate).toEqual([mixinSpy, baseSpy, spy]) }) + + // vue-class-component#83 + it('should work for a constructor mixin', () => { + const spy = jasmine.createSpy('global mixin') + const Mixin = Vue.extend({ + created () { + spy(this.$options.myOption) + } + }) + + Vue.mixin(Mixin) + + new Vue({ + myOption: 'hello' + }) + expect(spy).toHaveBeenCalledWith('hello') + }) })