1.封装js,命名为message.js,代码如下:

/**防止重复点击重复弹出message弹框 */
import {Message} from 'element-ui';
let messageInstance = null;
const resetMessage = (options) => {
    if(messageInstance) {
        messageInstance.close()
    }
    messageInstance = Message(options)
}
;['error','success','info','warning'].forEach(type => {
    resetMessage[type] = options => {
        if(typeof options === 'string') {
            options = {
                message:options
            }
        }
        options.type = type
        return resetMessage(options)
    }
})
export const message = resetMessage

2.main.js引用message.js

import ElementUI from 'element-ui'
import {message} from './message.js';//引用message要在Vue.use(ElementUI)后面,不然没有效果
vue.prototype.$message = message;

 

Logo

前往低代码交流专区

更多推荐