vue-teleport-modal
Version:
## Before use 'vue-teleport-modal', you have to install and apply 'EventBus'
28 lines (23 loc) • 818 B
JavaScript
import Modal from './components/Modal';
const modals = [];
const defaultComponentName = 'modal'
export default {
install(app, options= {}) {
app.config.globalProperties.$modal = {
show(modalName, params) {
app.config.globalProperties.$eventBus.$emit('toggle-modal', modalName, true, params);
},
hide(modalName) {
app.config.globalProperties.$eventBus.$emit('toggle-modal', modalName, false);
},
hideAll() {
modals.forEach(modal => {this.hide(modal)})
},
regist(modalName) {
modals.push(modalName);
}
}
this.componentName = options.componentName || defaultComponentName
app.component(this.componentName, Modal)
}
}