vue中全局修改elementui,message修改时长

有几种不同的写法对应不同的修改方式,都写在main.js里

第一种

bash 复制代码
// this.$message.success('添加成功')

['success', 'warning', 'info', 'error'].forEach(type => {
    ElementUI.Message[type] = options => {
        if (typeof options === 'string') {
            options = {
                message: options
            };
            options.duration = 800
            // if (type == 'warning' || type == 'error') {
            //     options.showClose = true
            // }
        }
        options.type = type;
        return ElementUI.Message(options);
    };
});

第二种

bash 复制代码
// this.$message({
//     message: '添加成功',
//     type: 'success'
// });
Vue.prototype.$message = function(msg){
    //根据msg对象中的type类型判断消息提示的类型
    let msgObj = {
      message:msg.message?msg.message:msg,
      duration: 800
    }
    let msgType = msg.type || ""
    switch(msgType) {
      case 'success':
        return  ElementUI.Message.success(msgObj);
      case 'warning':
        return  ElementUI.Message.warning(msgObj);
      case 'error':
        return  ElementUI.Message.error(msgObj);
      default:
        return  ElementUI.Message(msgObj);
    }
  }

第三种

bash 复制代码
// this.$message1( "添加成功" ,"success");
Vue.prototype.$message1 = function(msg, msgBg) {
    return ElementUI.Message({
        message: msg,
        duration: 800,
        type: msgBg,
        // showClose:true
    })
};
相关推荐
遇见~未来9 小时前
第六篇_CSS进阶_深入浏览器与工程化
前端·css·rust
Cache技术分享10 小时前
397. Java 文件操作基础 - 创建常规文件与临时文件
前端·后端
Daybreak10 小时前
Vercel Serverless 调国内 AI 接口 504?Edge Runtime 救了我
前端
zubylon10 小时前
Ollama 本地起一个开发助手
前端·人工智能
遇见~未来10 小时前
第五篇_构建真实页面_组件_响应式_维护性
前端·css3
魔士于安10 小时前
Unity完整小球迷宫项目
前端·unity·游戏引擎·贴图·模型
irpywp10 小时前
苦于AI生成的网页千篇一律且粗糙?design-md-chrome :一款网页样式提取插件 ,将任意网站的视觉规范转化为大模型可读的代码指令!
前端·人工智能·chrome·开源·github
xingpanvip10 小时前
星盘接口开发文档:日运语料接口指南
android·开发语言·前端·css·php·lua
网络点点滴10 小时前
Node.js理论-Web的基本运作原理
前端·node.js
宝宝宝阿11 小时前
前端访问后台接口存在跨域问题,如何处理解决
前端