You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

28 lines
663 B

import toast from './index.vue'
export default {
// 注册Toast
install(Vue) {
Vue.prototype.$MyToast = (text, opts) => {
// 设置默认参数,可设置多个
let defaultOpts = {
duration: 2000
}
opts = Object.assign(defaultOpts, opts);
// 生成一个Vue的子类
let toastTpl = Vue.extend(toast);
// 生成一个该子类的实例
let tpl = new toastTpl({
data : opts
}).$mount();
// 并将此div加入全局挂载点内部
document.body.appendChild(tpl.$el);
// 修改提示语
tpl.text = text;
// 定时消失
setTimeout(() => {
document.body.removeChild(tpl.$el);
}, opts.duration)
}
}
}