vue-toast-demo-3
Version:
a toast plugin for mobile
48 lines (37 loc) • 1.21 kB
JavaScript
import ToastComponet from './vue-toast.vue';
let Toast = {};
Toast.install = function (Vue,options) {
var opt = {
duration: 3000
};
for (var key in options) {
opt[key] = options[key];
}
Vue.prototype.$toast = function (message,option) {
if (typeof option == 'object') {
for (var key in options) {
opt[key] = options[key];
}
}
const ToastController = Vue.extend(ToastComponet);
var instance = new ToastController().$mount(document.createElement("div"));
instance.message = message;
instance.visible = true;
document.body.appendChild(instance.$el);
setTimeout(()=>{
instance.visible = false;
document.body.removeChild(instance.$el);
},opt.duration)
};
Vue.prototype.$toast['show'] = function (message,option) {
Vue.prototype.$toast(message,option);
};
// Vue.prototype.$toast['success'] = function (message,option) {
// Vue.prototype.$toast(message,option);
// }
};
//必须Vue要使用
if (window.Vue) {
Vue.use(Toast);
}
export default Toast;