优化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>
相关推荐
IT_陈寒14 分钟前
SpringBoot高并发优化:这5个被忽视的配置让你的QPS提升300%
前端·人工智能·后端
光影少年21 分钟前
css优化都有哪些优化方案
前端·css·rust
BillKu29 分钟前
npm 安装命令中关于 @ 的讲解,如:npm install @vue-office/docx vue-demi
前端·vue.js·npm
bestadc32 分钟前
LeetCode 几道 Promises 和 Time 的题目
javascript·算法·leetcode
yangzhi_emo42 分钟前
ES6笔记4
前端·笔记·es6
萌萌哒草头将军1 小时前
Node.js v24.8.0 新功能预览!🚀🚀🚀
前端·javascript·node.js
超人不会飛1 小时前
大模型应用 Vue H5 模板:快速落地流式交互与富文本渲染的开箱方案
前端·vue.js·github
用户458203153171 小时前
CSS无需JavaScript的交互效果实现
前端·css
影i1 小时前
在 Vue + Codemirror 中优雅回显 JSON
前端
奇怪的前端71 小时前
Alien-Signals 响应式系统
前端·vue.js