Skip to content

Commit 7885b28

Browse files
committed
make sure plugin install only once
1 parent 29ebc2b commit 7885b28

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/debug.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export function warn(msg) {
2-
console.error(`[create-api warn]: ${msg}`)
2+
console.error(`[vue-create-api warn]: ${msg}`)
33
}
44

55
export function assert(condition, msg) {
66
if (!condition) {
7-
throw new Error(`[create-api error]: ${msg}`)
7+
throw new Error(`[vue-create-api error]: ${msg}`)
88
}
99
}
1010

1111
export function tip(msg) {
12-
console.warn(`[create-api tip]: ${msg}`)
12+
console.warn(`[vue-create-api tip]: ${msg}`)
1313
}

src/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { camelize, escapeReg, isBoolean } from './util'
2-
import { assert } from './debug'
2+
import { assert, warn } from './debug'
33
import apiCreator from './creator'
44

5+
let installed = false
6+
57
function install(Vue, options = {}) {
8+
if (installed) {
9+
warn('[vue-create-api] already installed. Vue.use(CreateAPI) should be called only once.')
10+
return
11+
}
12+
installed = true
613
const {componentPrefix = '', apiPrefix = '$create-'} = options
714

815
Vue.createAPI = function (Component, events, single) {

0 commit comments

Comments
 (0)