1 |
|
2 |
|
3 | import { toArray } from '../util/index'
|
4 |
|
5 | export function initUse (Vue: GlobalAPI) {
|
6 | Vue.use = function (plugin: Function | Object) {
|
7 | const installedPlugins = (this._installedPlugins || (this._installedPlugins = []))
|
8 | if (installedPlugins.indexOf(plugin) > -1) {
|
9 | return this
|
10 | }
|
11 |
|
12 |
|
13 | const args = toArray(arguments, 1)
|
14 | args.unshift(this)
|
15 | if (typeof plugin.install === 'function') {
|
16 | plugin.install.apply(plugin, args)
|
17 | } else if (typeof plugin === 'function') {
|
18 | plugin.apply(null, args)
|
19 | }
|
20 | installedPlugins.push(plugin)
|
21 | return this
|
22 | }
|
23 | }
|