UNPKG

caiku-ui

Version:

caiku-ui for caiku

39 lines (35 loc) 947 B
const Vue = require('vue'); const toastComponent = require('./src/index.vue').default; const ToastConstructor = Vue.extend(toastComponent); function ckToast(toastParam, liveTime = 2500) { let toastData = null; if (typeof toastParam === 'string') { toastData = { type: 'prompt', msg: toastParam }; } else { toastData = toastParam; } !toastData.type ? toastData.type = 'prompt' : null; const toastDom = new ToastConstructor({ el: document.createElement('div'), data() { return { toastData, show: false }; } }); document.body.appendChild(toastDom.$el); setTimeout(() => { toastDom.show = false; setTimeout(() => { document.body.removeChild(toastDom.$el); }, 500); }, liveTime); } module.exports = { ckToast, toastComponent };