vue处理Element-UI中message重复跳出的情况

utils包中新建 optimizePop.js文件

javascript 复制代码
// 重置 message,防止重复点击重复弹出 message 弹框
import { Message } from 'element-ui'
let messageInstance = null
const mainMessage = options => {
  // 如果弹窗已存在先关闭
  if (messageInstance) messageInstance.close()
      messageInstance = Message(options)
}
const arr = ['success', 'warning', 'info', 'error']
arr.forEach(type => {
  mainMessage[type] = options => {
    if (typeof options === 'string') {
      options = {
        message: options
      }
    }
    options.type = type
    return mainMessage(options)
  }
})
const message = mainMessage
export default message

main.js中导入

javascript 复制代码
Vue.use(ElementUI);
import message from './utils/optimizePop.js' //引入
Vue.prototype.$message = message //重写message提示框,注意: 此行代码一定要放在vue.use(ElementuI)后面,否则不生效
相关推荐
JiangJiang2 分钟前
🩸 一次失败的降级迁移尝试 **从 Vite + React 19 到 CRA + React 17 的 IE 兼容血泪史**
前端
moyu844 分钟前
静态声明与动态拦截:从Object.defineProperty到Proxy
前端
kuxku18 分钟前
下一代前端工具链浅析
前端·架构
清风不问烟雨z20 分钟前
不仅仅是 Mock 服务:mock-h3,让前端也能优雅拥有后端能力
前端·javascript·vite
跟橙姐学代码21 分钟前
写 Python 函数别再死抠参数了,这招让代码瞬间灵活
前端·python
前端老鹰22 分钟前
CSS backdrop-filter:给元素背景添加模糊与色调的高级滤镜
前端·css·html
一枚前端小能手26 分钟前
⚡ Node.js服务器慢得像蜗牛,性能优化实战分享
前端·node.js·dnodejs
Lsx_41 分钟前
TypeScript 是怎么去查找类型定义的?
前端·javascript·typescript
xianxin_1 小时前
CSS Dimension(尺寸)
前端
小宋搬砖第一名1 小时前
前端包体积优化实战-从 352KB 到 7.45KB 的极致瘦身
前端