Skip to content

Commit 049f317

Browse files
Kingwlyyx990803
authored andcommitted
fix: support plugin with multi version vue (#5985)
close #5970
1 parent 27a1b03 commit 049f317

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/core/global-api/use.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { toArray } from '../util/index'
44

55
export function initUse (Vue: GlobalAPI) {
66
Vue.use = function (plugin: Function | Object) {
7-
const cid = this.cid
8-
if (!plugin._installed) {
9-
plugin._installed = {}
10-
}
11-
if (plugin._installed[cid]) {
7+
const installedPlugins = (this._installedPlugins || (this._installedPlugins = []))
8+
if (installedPlugins.indexOf(plugin) > -1) {
129
return this
1310
}
11+
1412
// additional parameters
1513
const args = toArray(arguments, 1)
1614
args.unshift(this)
@@ -19,7 +17,7 @@ export function initUse (Vue: GlobalAPI) {
1917
} else if (typeof plugin === 'function') {
2018
plugin.apply(null, args)
2119
}
22-
plugin._installed[cid] = true
20+
installedPlugins.push(plugin)
2321
return this
2422
}
2523
}

test/unit/features/global-api/use.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,20 @@ describe('Global API: use', () => {
3333
expect(Vue.options.directives['plugin-test']).toBeUndefined()
3434
expect(Ctor.options.directives['plugin-test']).toBe(def)
3535
})
36+
37+
// Github issue #5970
38+
it('should work on multi version', () => {
39+
const Ctor1 = Vue.extend({})
40+
const Ctor2 = Vue.extend({})
41+
42+
Ctor1.use(pluginStub, options)
43+
expect(Vue.options.directives['plugin-test']).toBeUndefined()
44+
expect(Ctor1.options.directives['plugin-test']).toBe(def)
45+
46+
// multi version Vue Ctor with the same cid
47+
Ctor2.cid = Ctor1.cid
48+
Ctor2.use(pluginStub, options)
49+
expect(Vue.options.directives['plugin-test']).toBeUndefined()
50+
expect(Ctor2.options.directives['plugin-test']).toBe(def)
51+
})
3652
})

0 commit comments

Comments
 (0)