vue中对element的弹框messagebox的二次封装

在vue中对确认框的二次封装

使用场景:在页面中做某些需要警告的操作时的弹框提示


1、在utils文件夹下新建一个confirm.js文件来对messageBox的封装,内容如下:

/** confirm.js */
import { MessageBox } from 'element-ui'

export function handleCofirm(text = '确定执行此操作吗?', type = 'warning') {
  return MessageBox.confirm(text, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: type,
    center: true
  })
}

2、使用

import { handleCofirm } from '@/utils/confirm'
export default {
    deleteDomain(row) {
      handleCofirm('确认删除该标签吗?', 'warning',).then(res => {
         // 
      }).catch(err => {
        console.log('err', err) // cancel
        // 
      })
    }
  
}
原文地址:https://www.cnblogs.com/llff123/p/11309144.html