Is your button within a livewire component?
Livewire $emit on wire:click
Hello,
I have a button that needs to $emit something on click. And since I am using Livewire in this project, I am using the wire:click function.
I have other buttons that is using the wire:click which also has a $emit in them. But for some reason, I can't see what I have done wrong, I have even copy/pasted one of he buttons that work...
<!-- show.blade.php -->
<span class="inline-flex rounded-md shadow-sm">
<button wire:click="$emit('deleteProduct')" type="button" class="...">
Delete
</button>
</span>
<livewire:delete-product :product="$product"/>
class DeleteManual extends Component
{
public $isOpen = false;
public $listeners = ['deleteProduct'];
public $manual;
public function mount(Product $product)
{
$this->product= $product;
}
public function deleteProduct()
{
$this->isOpen = true;
}
...
}
At this moment I am just trying to show something on the page, if $isOpen is true.
If I manually edit the default to true, it is showing up.
But button doesn't show it, if I click on it.
wire:click and $emit will only work within the scope of a livewire component.
Elsewhere, use window.livewire.emit('deleteProduct') and trigger it from on-click or using alpine
Please or to participate in this conversation.