Element-UI Message Box 使用$msgbox方法自定义模版内容,修改默认样式

实际效果图:

 

代码:

    changeMsgbox (){
      let item = {
        name: '肯德鸡超级星期四'
      }
      const h = this.$createElement;
      this.$msgbox({
        title: '提示',
        message: h('p', undefined, [
          h('div', undefined, `当前优惠券[${item.name}],可能已过期`),
          h('span', undefined, '如需查询最新优惠信息,请扫码关注公众号【'),
          h('span', { 
            style: 'color: #409EFF;cursor: pointer;text-decoration: underline;' ,
            on: {
              click: () => {
                this.goDetail()
                this.$msgbox.close()
              }
            }}, '【立即前往肯德鸡】'),
          h('span', undefined, '】'),
        ]),
        type: 'warning',
        showCancelButton: true,
        showConfirmButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '关闭',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            this.goToKFC(item, instance, done)
            console.log('确定')
          } else {
            done();
            console.log('关闭')
          }
        }
      }).then(() => {
        
      }).catch(() => {
          
      });
     }


    goDetail() {
        //todo
    },
    goToKFC(item, instance, done) {
      instance.confirmButtonLoading = true;
      let params = {
        id: item.id,
      }
      API(params).then(res => {
        if (res.code == '200') {
          //todo
          this.$message.success('成功!')
          done();
          instance.confirmButtonLoading = false;
        }
      })
    },
 注意:

接口请求成功只 返回  Promise {<pending>}???

原因分析:

原因在promise返回中,主要是在一个异步请求方法(方法1)中使用了另一个异步请求方法(方法2),在方法2中存在返回值

解决方法:只需要在方法1中使用方法2的前面加上await就可以了


    async goToKFC(item, instance, done) {
      instance.confirmButtonLoading = true;
      let params = {
        id: item.id,
      }
      const res = await API(params)
      if (res && res.code === 200) {
        this.$message.success('成功!')
        done();
        instance.confirmButtonLoading = false;
      }
    },

这样就完美解决了问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Aotman_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值