I used the sweetAlert cdn, but not working. I’m working with Laravel 9 and Livewire 2.12
In my app.blade.php, added the @stack directive:
@stack directive in my app.blade.php file
So, in my component dashboard.blade.php I tried this:
@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
Livewire.on('mostrarAlerta', vacanteId => {
Swal.fire({
title: "¿Eliminar vacante?",
text: "Una vacante eliminada no se puede recuperar!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#524C42",
confirmButtonText: "Si, eliminar!"
cancelButtonText: "Cancelar"
}).then((result) => {
if (result.isConfirmed) {
Swal.fire({
title: "Eliminado!",
text: "La vacante ha sido eliminada!.",
icon: "success"
});
}
});
})
</script>
@endpush
In the browser console:
Scripts in the browser console
but not working.
I tried a simple alert and this worked:
@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
Livewire.on('mostrarAlerta', vacanteId => {
alert("Hola mundo! " + vacanteId )
})
</script>
@endpush
Alexis Tenorio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.