vue-atlas
Version:
A library of Vue.js 2.x components.
36 lines (27 loc) • 745 B
JavaScript
import Vue from 'vue'
import VaToastComponent from './VaToast'
const VaToast = Vue.extend(VaToastComponent)
export default function (obj) {
const domNode = document.createElement('div')
document.body.appendChild(domNode)
const options = {
el: domNode,
propsData: {}
}
const allowedProps = ['text', 'placement', 'type', 'duration', 'closeOnClick']
allowedProps.forEach((prop) => {
if (Object.keys(obj).includes(prop)) {
options.propsData[prop] = obj[prop]
}
})
const instance = new VaToast(options)
instance.show = true
if (instance.duration > 0) {
setTimeout(() => {
instance.show = false
Vue.nextTick(() => {
instance.$destroy()
})
}, instance.duration)
}
}