有些东西非常走心,更像是提醒着在路上的人们,勿忘初心甚至是找回初心
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: "已取消跳转新建"
});
});
原文:https://www.cnblogs.com/home-/p/11661820.html