项目3种弹框模式

一、需求

图片描述

二、使用插件 Sweetalert

在vue里面使用 vue-sweetalert

npm install vue-sweetalert --save
import VueSweetAlert from 'vue-sweetalert'
Vue.use(VueSweetAlert)

完整例子:(不需要的选项就不要设置,详情看文档)

this.$swal({
    title: '', // 标题
    text: 'You will not be able to recover this imaginary file!', // 文本
    type: 'warning', // 类型
    timer: 2000, // 弹框显示时间
    showCancelButton: true, 
    confirmButtonColor: '#DD6B55',
    confirmButtonText: 'Yes, delete it!'
  }).then(() => { // 点击确认按钮执行的操作
    this.$swal('Deleted!', 'Your imaginary file has been deleted.', 'success')
  }, () => { // 点击取消按钮执行的操作
    this.$swal('Cancle!', 'Your imaginary file has been cancled.', 'success')
  }).catch(this.$swal.noop) // 解决在vue中使用时的报错

三、注意事项

我在使用过程报错的几个地方

1.Uncaught (in promise) timer

解决:添加这样代码catch(this.$swal.noop)

this.$swal({...}).catch(this.$swal.noop)
2.选项报错 Unknown parameter "closeOnConfirm"

原因: 版本修改 Migration from SweetAlert to SweetAlert2 跟前面的文档个别选项设置有冲突,本项目看这个

四、代码复制

第1、2种

this.$swal({
        title: 'Title',
        text: 'You will not be able to recover this imaginary file!',
      }).catch(this.$swal.noop)

第3种

this.$swal({
    title: '', // 标题
    text: 'You will not be able to recover this imaginary file!', // 文本
    type: 'warning', // 类型
    timer: 2000, // 弹框显示时间
    showCancelButton: true, 
    confirmButtonColor: '#DD6B55',
    confirmButtonText: 'Yes, delete it!'
  }).then(() => { // 点击确认按钮执行的操作
    this.$swal('Deleted!', 'Your imaginary file has been deleted.', 'success')
  }, () => { // 点击取消按钮执行的操作
    this.$swal('Cancle!', 'Your imaginary file has been cancled.', 'success')
  }).catch(this.$swal.noop) // 解决在vue中使用时的报错
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值