如何把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'); } } },
标签:MessageBox,return,confirm,elm,await,awit,let,js 来源: https://www.cnblogs.com/qiaozhiming123/p/15594438.html