import msgboxVue from './index.vue';
// 定义插件对象
const MessageBox = {};
// vue的install方法,用于定义vue插件
MessageBox.install = function (Vue,options) {
const MessageBoxInstance = Vue.extend(msgboxVue);
let currentMsg,instance;
const initInstance = () => {
// 实例化vue实例
currentMsg = new Message
BoxInstance();
let msg
BoxEl = currentMsg.$mount().$el;
document.body.appendChild(msg
BoxEl);
};
// 在Vue的原型上
添加实例
方法,以全局
调用
Vue.prototype.$msg
Box = {
showMsg
Box (options) {
if (!instance) {
initInstance();
}
if (typeof options === 'string') {
currentMsg.content = options;
} else if (typeof options === 'object') {
Object.assign(currentMsg,options);
}
return currentMsg.showMsg
Box();
}
};
};
export default Message
Box;
{
// ...
}).catch(() => {
// ...
});