场景
问题: 有一个在项目非常常用的确认弹框, 并且使用element-ui的 messageBox;
我们不想在每一业务中大量的复制那么多的代码,
解决办法: 封装一个函数调用,尽可能给出操作回调
代码
代码连接 github
import {MessageBox} from 'element-ui';
Vue.prototype.$msgbox = MessageBox;
//msgbox.ts
function msgbox(
vm: any,
title: string = '消息',
text: string,
smallText: string = '',
isClose: boolean = false,
callback?: any,
success?: any,
cancel?: any,
smallStyle: string = 'color: #cacaca',
) {
const h = vm.$createElement;
vm.$msgbox({
title: title,
message: h('div', null, [
h('p', null, text),
h('span', {style: smallStyle}, smallText)