Imagine you have big data that needs to be loaded into a table. Besides the Lazy Loading component, another method uses wire:loading
directive which has a bit more features.
First, add a div
element with the wire:loading
directive above the table.
resources/views/livewire/products.blade.php:
<div class="space-y-6"> <div class="space-x-8"> // ... </div> <div class="text-red-600" wire:loading>Loading...</div> <div class="min-w-full align-middle"> // ... </div> {{ $products->links() }}</div>
Simulate longer loading by adding sleep(1)
to the Livewire component render
method. Then try to search, and you should see a red text saying Loading...
.
The wire:loading
directive also accepts adding or removing class parameters. For example, we can add opacity to the table while loading.
resources/views/livewire/products.blade.php:
<div class="space-y-6"> // ... <div class="text-red-600" wire:loading>Loading...</div> <div class="min-w-full align-middle" wire:loading.class="opacity-50"> // [tl! highlight] // ... </div> {{ $products->links() }}</div>
You can target a specific action by adding the wire:target="methodName"
directive.
<form wire:submit="save"> <!-- ... --> <button type="submit">Save</button> <button type="button" wire:click="remove">Remove</button> <div wire:loading wire:target="remove"> // [tl! highlight] Removing post... </div></form>
You can read more about Loading States in the official documentation.
why, when I write something, the first time the download works and gives out posts, the next process does not work just loading and opacity-50
Can you expand on this? Not sure I fully understand what you had in mind
Hey Polivas, The "You can target a specific action by adding the wire:target="methodName" directive." looks like don't belongs to this class, but if it does, sorry, I just don't understand the context.
Thanks sir.
In this example we have a button with an action
remove
. Where we usewire:loading
we alsp use thewire:target
and specify thatremove
method. This means whileremove
is being executed thewire:loading
div will be active. Hope this helps.Thank you very much Nerijus, now I understood the point.
I search for the lesson of how to make the loading indicator at Livewire , alpine js and Js I see this lesson at laraveldaily but now i can't get useful result from the search
If you need help will need more than that