优化elementUI的Message消息提示连续触发,满屏显示问题

elMessage.js

javascript 复制代码
import {Message} from 'element-ui'
const tipsEvent=(options)=>{
    console.log(document.querySelectorAll('.el-message'));
    const dom=document.querySelectorAll('.el-message')[0]
    if(dom==undefined){
        Message(options)
    }
}
const typeList=['success','error','info','warning']
typeList.forEach(item=>{
    tipsEvent[item]=options=>{
        const ele=document.querySelectorAll('.el-message')[0]
        if(ele==undefined){
            Message[item](options)
        }
    }
})
export const tips=tipsEvent

main.js中全局挂载

javascript 复制代码
import Vue from 'vue'
import {tips} from '@/utils/elMessage.js'

Vue.prototype.$message=tips;//在这里建议取相同的名称,因为是为了覆盖框架默认的this.$message

index.vue中使用

javascript 复制代码
<script>
    export default {
        name: 'index',
        methods: {
            handleTap(){
              this.$message({
                type:'warning',
                message:'警告提示触发了'
              })
            }
        }
    }
</script>
相关推荐
Moment19 小时前
Vibe Coding 时代,到底该选什么样的工具来提升效率❓❓❓
前端·后端·github
IT_陈寒21 小时前
SpringBoot性能飙升200%?这5个隐藏配置你必须知道!
前端·人工智能·后端
小时前端21 小时前
React性能优化的完整方法论,附赠大厂面试通关技巧
前端·react.js
Nicko1 天前
Jetpack Compose BOM 2026.02.01 解读与升级指南
前端
小蜜蜂dry1 天前
nestjs学习 - 控制器、提供者、模块
前端·node.js·nestjs
优秀稳妥的JiaJi1 天前
基于腾讯地图实现电子围栏绘制与校验
前端·vue.js·前端框架
前端开发呀1 天前
从 qiankun(乾坤) 迁移到 Module Federation(模块联邦),对MF只能说相见恨晚!
前端
Lee川1 天前
深度解构JavaScript:作用域链与闭包的内存全景图
javascript·面试
没想好d1 天前
通用管理后台组件库-10-表单组件
前端
恋猫de小郭1 天前
你用的 Claude 可能是虚假 Claude ,论文数据告诉你,Shadow API 中的欺骗性模型声明
前端·人工智能·ai编程