Skip to content

Commit

Permalink
fix: support plugin with multi version vue (#5985)
Browse files Browse the repository at this point in the history
close #5970
  • Loading branch information
Kingwl authored and yyx990803 committed Jun 30, 2017
1 parent 27a1b03 commit 049f317
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/global-api/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { toArray } from '../util/index'

export function initUse (Vue: GlobalAPI) {
Vue.use = function (plugin: Function | Object) {
const cid = this.cid
if (!plugin._installed) {
plugin._installed = {}
}
if (plugin._installed[cid]) {
const installedPlugins = (this._installedPlugins || (this._installedPlugins = []))
if (installedPlugins.indexOf(plugin) > -1) {
return this
}

// additional parameters
const args = toArray(arguments, 1)
args.unshift(this)
Expand All @@ -19,7 +17,7 @@ export function initUse (Vue: GlobalAPI) {
} else if (typeof plugin === 'function') {
plugin.apply(null, args)
}
plugin._installed[cid] = true
installedPlugins.push(plugin)
return this
}
}
16 changes: 16 additions & 0 deletions test/unit/features/global-api/use.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ describe('Global API: use', () => {
expect(Vue.options.directives['plugin-test']).toBeUndefined()
expect(Ctor.options.directives['plugin-test']).toBe(def)
})

// Github issue #5970
it('should work on multi version', () => {
const Ctor1 = Vue.extend({})
const Ctor2 = Vue.extend({})

Ctor1.use(pluginStub, options)
expect(Vue.options.directives['plugin-test']).toBeUndefined()
expect(Ctor1.options.directives['plugin-test']).toBe(def)

// multi version Vue Ctor with the same cid
Ctor2.cid = Ctor1.cid
Ctor2.use(pluginStub, options)
expect(Vue.options.directives['plugin-test']).toBeUndefined()
expect(Ctor2.options.directives['plugin-test']).toBe(def)
})
})

0 comments on commit 049f317

Please sign in to comment.