Skip to content

Commit 716d20c

Browse files
author
Guillaume Chau
committed
Auto install
1 parent 7793a68 commit 716d20c

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/index.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
import _VirtualScroller from './components/VirtualScroller.vue'
1+
import VirtualScroller from './components/VirtualScroller.vue'
22

3-
export function install (Vue) {
4-
Vue.component('virtual-scroller', _VirtualScroller)
3+
export {
4+
VirtualScroller,
55
}
66

7-
export const VirtualScroller = _VirtualScroller
7+
function registerComponents (Vue, prefix) {
8+
Vue.component(`${prefix}virtual-scroller`, VirtualScroller)
9+
}
810

9-
export default {
10-
/* eslint-disable no-undef */
11+
const plugin = {
12+
// eslint-disable-next-line no-undef
1113
version: VERSION,
12-
install,
14+
install (Vue, options) {
15+
const finalOptions = Object.assign({}, {
16+
installComponents: true,
17+
componentsPrefix: '',
18+
}, options)
19+
20+
if (finalOptions.installComponents) {
21+
registerComponents(Vue, finalOptions.componentsPrefix)
22+
}
23+
},
24+
}
25+
26+
export default plugin
27+
28+
// Auto-install
29+
let GlobalVue = null
30+
if (typeof window !== 'undefined') {
31+
GlobalVue = window.Vue
32+
} else if (typeof global !== 'undefined') {
33+
GlobalVue = global.Vue
34+
}
35+
if (GlobalVue) {
36+
GlobalVue.use(plugin)
1337
}

0 commit comments

Comments
 (0)