1,新建文件resetMessage.js
/** 重置message,防止重复点击重复弹出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)
}
})
let messageup
export default messageup = resetMessage
2,页面引用
import messageup from '@/utils/resetMessage'
messageup({
type: 'warning',
showClose: false,
message: '文件名格式不正确'
})