UNPKG

yukaka

Version:
31 lines (29 loc) 832 B
import Toast from './toast' let currentToast export default { install (Vue,options){ Vue.prototype.$toast=function(message,toastOptions) { if (currentToast) { currentToast.close() } currentToast = createToast({ Vue, message, propsData:toastOptions, onClose:()=>{ currentToast=null } }) } } } function createToast({Vue,message,propsData,onClose}){ let Constructor = Vue.extend(Toast); let toast = new Constructor({propsData}); toast.$slots.default = message; //slots放在$mount前面 toast.$mount(); toast.$on('close',onClose); document.body.appendChild(toast.$el); return toast }