如何把elm中的MessageBox(pamise)封装成awit的写法

1.新建文件messageBox.js

import { MessageBox } from 'element-ui';

function confirm (
  content,
  title = '提示',
  settings = {},
) {
  let messageSetting = {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
    ...settings
  }
  return MessageBox.confirm(content, title, messageSetting).then(() => {
    return true;
  }).catch(() => {
    return false;
  });
}


export default confirm

2.在main.js中引用,全局挂载

import confirm from '@/utils/messageBox.js'
Vue.prototype.$confirm = confirm

3.在其他组件中使用

async defaultEmail(row) {
      let control = await this.$confirm('是否替换当前默认邮箱?', '提示')
      if (control) {
        let res = await emailApi.defaultEmail({ id: row.id });
                if (res) {
                    this.$message.success(`默认邮箱设置成功`);
                      await this.$store.dispatch('getEmailList');
                }
      }
        },

 

上一篇:Windows 编程(多进程)


下一篇:⑤用户列表:删除按钮实现