创建:\src\utils\messageBox.js
/**
* elementUI messageBox 方法封装
*/
import {MessageBox} from "element-ui";
//确认弹窗
/*
使用:
handleConfirm('确定执行此操作吗?', 'warning' , '标题').then(res => {
// do something
}).catch(err => {
// do something cancel
});
*/
let handleConfirm = (text = '确定执行此操作吗?', type = 'warning' , title= '提示') => {
return MessageBox.confirm(text, title, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: type,
center: true
})
};
//alert弹窗
/*
使用:
handleAlert('提交数据成功!', 'success')
.then(res => {
// then() 可省略
})
*/
let handleAlert = (text = '操作成功。', type = 'success') => {
return MessageBox.confirm(`<span style="font-size: 1.2rem;margin-top: -1rem;margin-bottom: 0.4rem;display: block;">${text}</span>`, {
confirmButtonText: '关闭',
cancelButtonText: '',
showCancelButton:false,
dangerouslyUseHTMLString:true,
type: type,
center: true
})
};
export {handleConfirm,handleAlert}
组件中使用:
import {handleConfirm,handleAlert} from "@/utils/messageBox" ;
//确认弹窗
handleConfirm('确定执行此操作吗?', 'warning' , '标题').then(res => {
// do something
}).catch(err => {
// do something cancel
});
//alert弹窗
handleAlert('提交数据成功!', 'success')
.then(res => {
// then() 可省略
})