SweetAlert2 with Vue 3 and <script setup>

Viewed 657

I have the Laravel/Inertia app and I use VueSweetAlert2 imported globally in app.js. It works well on every component. But now, I want to use on the component and I can't find working solution for sweetalert. I've tried several ways, but sweetalert still doesn't work.

I tried:

   const swal = inject($swal),

   Import VueSweetAlert2 from 'vue-sweetalert2';

   Import Swal from 'vue-sweetalert2';

   Import swal from 'vue-sweetalert2';

and some other ways.

How can I use SweetAlert in <script setup>???

Thanks. Pato

1 Answers
<script setup>
import { inject } from 'vue'
const swal = inject('$swal')

function showDialog(event) {
    swal.fire({
        icon: 'success',
        title: 'done',
        showConfirmButton: false,
        timer: 1500
    });
}
</script>

Reference from calling SweetAlert2 inside Async method in VUE 3

Related