环境:vue+element-ui
问题:重复点击按钮或多个请求同时报错时弹出多个提示框
解决办法:重写message,下一个弹框显示时关闭上一个弹框
message.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)
}
})
export const message = resetMessage
main.js
import ElementUI from 'element-ui'
import {message} from './message.js';
vue.prototype.$message = message;