forms/src/plugins/plugin.js

31 lines
1 KiB
JavaScript
Raw Normal View History

2019-05-14 01:15:45 +02:00
// we need our modal component
import ModalDialog from './ModalDialog'
2019-05-14 01:15:45 +02:00
const Modal = {
// every plugin for Vue.js needs install method
// this method will run after Vue.use(<your-plugin-here>) is executed
install(Vue, options) {
// We must create new Eventbus
// which is just another Vue instance that will be listening for and emiting events from our main instance
// this EventBus will be available as Modal.EventBus
this.EventBus = new Vue()
// making our modal component global
// eslint-disable-next-line vue/match-component-file-name
Vue.component('ModalDialog', ModalDialog)
2019-05-14 01:15:45 +02:00
// exposing global $modal object with method show()
// method show() takes object params as argument
// inside this object we can have modal title, text, styles... and also our callback confirm function
Vue.prototype.$modal = {
show(params) {
// if we use this.$modal.show(params) inside our original Vue instance
// we will emit 'show' event with parameters 'params'
Modal.EventBus.$emit('show', params)
},
2019-05-14 01:15:45 +02:00
}
},
2019-05-14 01:15:45 +02:00
}
export default Modal