62.《关于ElementUI中confirm确认弹窗的封装整理》


title: 12.《关于ElementUI中confirm确认弹窗的封装整理》
date: 2021-03-07 14:39:14


封装的ElementUI中confirm确认弹窗

在实际项目开发中,我们删除某一项时,都会有一个弹框让您进行确认操作,这样你会写无数个弹框,非常麻烦,所以,为了方便,个人对弹框进行了封装,希望大家能有所成长

1.将封装的代码挂在到原型对象上,任何地方通过 this 可以访问,element.js 最终要在 main.js中导入,如果你在原型对象上进行了挂在,就不用导入了

element.js

Vue.prototype.$confirm= (text) => {
  return new Promise((resolve, reject) => {
    MessageBox.confirm(text, '提示',{
      confirmButtonClass: 'btnFalses' 
    }, {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then((res) => { 
      resolve(true)
    }).catch((res) => { 
      Message.info('已取消')
      reject(false)
    })
  }).catch(() => {
    // 可对错误进行处理
  })
}

2.在相应的vue组件进行使用

 <el-table-column label="操作" width="400">
              <span class="opan" @click="$router.push('/specAction/specDetalis')">查看详情</span>
              <span class="opan">编辑</span>
              <span class="opan">更新</span>
              <span class="opan" @click="del">删除</span> 
  </el-table-column>
  
 methods: {
     // 删除
     async  del(){ 
          const res = await this.$confirm('确认要删除吗?')
           if(res){
             this.$success("你确认惹删除!")
           }
       },
 } 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值