plug-in code
import IndexComponent from "./index";
let $vm;
export default {
install(Vue, options) {
const TipsController = Vue.extend(IndexComponent);
$vm = new TipsController().$mount(document.createElement("div"));
document.body.appendChild($vm.$el);
let Tips = {
info(title, time = 2) {
this.init(title, time, "info");
},
success(title, time = 2) {
this.init(title, time, "success");
},
warning(title, time = 2) {
this.init(title, time, "warning");
},
error(title, time = 2) {
this.init(title, time, "error");
},
init(title, time, type) {
Object.assign($vm, {
title: title,
type: type,
show: true
});
setTimeout(() => {
$vm.show = false
}, time * 1000)
}
};
if (! Vue.prototype.$Tips) {
Vue.prototype.$Tips = Tips;
}
}
}
call in the vue component:
this.$Tips.success ("hello wordings")
achieve the effect
axios ?