livewire loaded event code example

Example 1: livewire event

inside livewire controller
$this->emit('eventName');

inside livewire blade file
<script type="text/javascript">
    window.onload = function() {
        Livewire.on('eventName', () => {
           // Code Here
        })
    }
</script>

Example 2: detect livewire is loading in javascript

window.livewireLoading = false;

document.addEventListener("DOMContentLoaded", () => {
    Livewire.hook('message.sent', (message, component) => {
        livewireLoading = true;
    })

    Livewire.hook('message.processed', (message, component) => {
        livewireLoading = false;
    })
});

Tags:

Misc Example