【问题标题】:How to configure SweetAlert properly in Vue CLI如何在 Vue CLI 中正确配置 SweetAlert
【发布时间】:2020-07-24 15:01:48
【问题描述】:

这是我的配置和步骤。

1- 来自终端

npm install sweetalert2

2- 在 main.js 中

import Swal from 'sweetalert2'

window.swal = Swal;
Vue.use(Swal);
// Toast config
const toast = Swal.mixin({
  toast: true,
  position: 'top-end',
  showConfirmButton: false,
  timer: 3000,
  timerProgressBar: true,
  onOpen: (toast) => {
      toast.addEventListener('mouseenter', Swal.stopTimer)
      toast.addEventListener('mouseleave', Swal.resumeTimer)
  }
});
window.toast = toast;

3- 在视图中的使用

toast.fire({
    icon: 'success',
    title: 'Record has been updated.'
})

错误/问题:

237:5  error  'toast' is not defined  no-undef

【问题讨论】:

    标签: vuejs2 sweetalert2


    【解决方案1】:

    window.toast代替const toast

    【讨论】:

      猜你喜欢
      • 2019-01-03
      • 2018-08-12
      • 2018-09-10
      • 2018-05-17
      • 1970-01-01
      • 2022-08-14
      • 2020-11-30
      • 2018-12-30
      • 2022-12-03
      相关资源
      最近更新 更多