UNPKG

my-showtoast

Version:

showToast

39 lines (34 loc) 850 B
import showToastComponent from './components/showToast.vue'; let $toastObj; export default { install(Vue, options) { // Vue.component(Textarea.name, Textarea) if (!$toastObj) { const ShowToastPlugin = Vue.extend(showToastComponent); $toastObj = new ShowToastPlugin({ el: document.createElement('div') }); document.body.appendChild($toastObj.$el); } $toastObj.show = false; let showToast = { show(txt) { if (txt && txt.trim()) { $toastObj.show = true; $toastObj.text = txt; } }, hide() { $toastObj.show = false; } }; if (!Vue.$showToast) { Vue.$showToast = showToast; } Vue.mixin({ created() { this.$showToast = Vue.$showToast; } }); } };