From 049f3171a9d2e97f62c209a4b78a71ec9dae810f Mon Sep 17 00:00:00 2001 From: "wenlu.wang" <805037171@163.com> Date: Fri, 30 Jun 2017 11:20:43 +0800 Subject: [PATCH] fix: support plugin with multi version vue (#5985) close #5970 --- src/core/global-api/use.js | 10 ++++------ test/unit/features/global-api/use.spec.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/core/global-api/use.js b/src/core/global-api/use.js index 24dcca2781..a5b69988dd 100644 --- a/src/core/global-api/use.js +++ b/src/core/global-api/use.js @@ -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) @@ -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 } } diff --git a/test/unit/features/global-api/use.spec.js b/test/unit/features/global-api/use.spec.js index a76d20e5a6..ca8e8f8eff 100644 --- a/test/unit/features/global-api/use.spec.js +++ b/test/unit/features/global-api/use.spec.js @@ -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) + }) })