elementUI MessageBox 方法封装

创建:\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() 可省略
     })
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。