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
    })
};
相关推荐
NickJiangDev2 分钟前
Elpis-Core 技术解析:从零构建一个基于 Koa 的企业级 Node.js 框架内核
前端
我要让全世界知道我很低调2 分钟前
来聊聊 Codex 高效编程的正确姿势
前端·程序员
NickJiangDev4 分钟前
Elpis Webpack 工程化实战:Vue 多页应用的构建体系搭建
前端
米饭同学i4 分钟前
GitLab CI/CD + Vue 前端 完整方案
前端
yuki_uix7 分钟前
遇到前端题目,我现在会先问自己这四个问题
前端·面试
Wect8 分钟前
JS 手撕:对象创建、继承全解析
前端·javascript·面试
PeterMap12 分钟前
Vue.js全面解析:从入门到上手,前端新手的首选框架
前端·vue.js
3秒一个大13 分钟前
深入理解 JS 中的栈与堆:从内存模型到数据结构,再谈内存泄漏
前端·javascript·数据结构
weixin_4138385613 分钟前
基于区块链的校园二手书交易系统
vue.js·spring·区块链·fabric
Mr_Xuhhh23 分钟前
深入Java多线程进阶:从锁策略到并发工具全解析
前端·数据库·python