【问题标题】:SweetAlert2 with Vue 3 and <script setup>SweetAlert2 与 Vue 3 和 <script setup>
【发布时间】:2022-08-09 12:48:16
【问题描述】:

我有 Laravel/Inertia 应用程序,我使用在 app.js 中全局导入的 VueSweetAlert2。 它适用于每个组件。但是现在,我想在组件上使用,我找不到 sweetalert 的工作解决方案。我已经尝试了几种方法,但 sweetalert 仍然不起作用。

我试过了:

   const swal = inject($swal),

   Import VueSweetAlert2 from \'vue-sweetalert2\';

   Import Swal from \'vue-sweetalert2\';

   Import swal from \'vue-sweetalert2\';

和其他一些方式。

如何在 <script setup> 中使用 SweetAlert???

谢谢。帕托

    标签: laravel vuejs3 sweetalert2 inertiajs vue-script-setup


    【解决方案1】:
    <script setup>
    import { inject } from 'vue'
    const swal = inject('$swal')
    
    function showDialog(event) {
        swal.fire({
            icon: 'success',
            title: 'done',
            showConfirmButton: false,
            timer: 1500
        });
    }
    </script>
    

    参考自 calling SweetAlert2 inside Async method in VUE 3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-25
      • 2021-11-20
      • 2021-12-28
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      • 2021-10-27
      • 2021-11-09
      相关资源
      最近更新 更多