This is the Livewire framework for Laravel
HTML:
<button wire:click="$emit('postAdded')">
PHP:
protected $listeners = ['postAdded' => 'showPostAddedMessage'];
public function showPostAddedMessage()
{
// Do stuff
}
public function render()
{
return view('livewire.index');
}
Clicking the button calls showPostAddedMessage() and after that render(). How can I listen for an event without calling render()?
I had the same issue. In my case, the render() method was closing my parent modal box. I just added "wire:ignore" in modal div. Livewire ignores that div whenever it calls the render() method
This is how livewire works. whenever you are changing anything / firing any event. the component will refresh. As far as I learned livewire, there is no way to stop it unless you are putting die() isnide showPOstAddedMessage function, which will be a very wierd way to solve it.
I've came to this sort of hack: if your concern is to not re-render the view, you can just return an empty string from render()
. The DOM will not be updated.
My case: I've got a download method that is not supposed to render anything.
public function download()
{
$this->skipRender();
}
public function render()
{
if($this->shouldSkipRender) {
return '';
}
return view("xxxxx");
}
As long as I'm not missing anything, this works for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.