首页 > 其他 > 详细

Vue简单封装一个elementUI消息确认框

时间:2019-10-12 15:35:25      阅读:797      评论:0      收藏:0      [点我收藏+]

有些东西非常走心,更像是提醒着在路上的人们,勿忘初心甚至是找回初心

Vue简单封装一个elementUI消息确认框

elementUI中的消息确认框在方法中触发就可以,但是会有很多地方用到所以简单封装一下( 下面的图是没有封装之前的 )

技术分享图片

 

 技术分享图片

 

 

下面开始封装:

 

 

 

 

 

封装:
挂载到Vue实例上也就是在main.js上写

第一个参数为确认框的内容,第二个参数为标题,第三个参数为配置项对象 ( msg、title、settings )
给他的原型加一个属性为$alertMsgBox ( 用的时候直接 this.$alertMsgBox("第一个参数","第二个参数")调用就可以)

Vue.prototype.$alertMsgBox = function alert(
  msg = "确认要删除该数据?",
  title = "提示",
  settings = {}
) {
  Object.assign(settings, {
    //合并对象
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    dangerouslyUseHTMLString: true //允许确认框内容为html格式
  });
  return this.$confirm(
    `<p style="font-weight:bold;">${msg}</p>`,
    title,
    settings
  );
};

 

使用:
this.$alertMsgBox("是否确认新建?", "系统示例")
        .then(() => {
          this.$router.push({ path: "/newEditUser" });
          this.$message({
            type: "success",
            message: "跳转新建成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消跳转新建"
          });
        });

技术分享图片

 

Vue简单封装一个elementUI消息确认框

原文:https://www.cnblogs.com/home-/p/11661820.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!