Reputation: 99
I am using Laravel 8, Livewire 2.x I am trying to using emit event, just created a simple button in my Livewire components
<button class="" wire:click="callme()">click me</button>
my component controller
public function callme()
{
$this->emitTo('Components.CustomizeModal', 'callFn');
}
Components/CustomizeModal controller
protected $listeners = [
'callFn' => 'whatever'
];
public function whatever()
{
dd("OK");
}
It was fired and the response is
{
"effects": {
"html": null,
"emits": [
{
"event": "callFn",
"params": [],
"to": "Components.CustomizeModal"
}
],
"dirty": []
},
"serverMemo": {
"checksum": "479fe7f16b16351c610955960c8299f45fd4aeed72d69f9cded044e3bff9a525"
}
}
it didn't fire the method at all, I have tried emit also, doesn't anyone has any idea?
Upvotes: 1
Views: 12308
Reputation: 367
Alternatively you can try to emit the event directly from the button.
<button wire:click="$emitTo('Components.CustomizeModal', 'callFn')">
and make sure
Components.CustomizeModal
is qualified livewire component and also mounted when the event is emitted otherwise it will fail
Upvotes: 1