same question :( can anyone help?
Jan 13, 2021
7
Level 3
How to call alpine JS method from livewire?
hi
I want to run alpinejs function from livewire component.
in posts component,
function gotcomment(){
$this->emit('gotcomment');
}
in posts view
<div wire:click="gotcomment">
I will get post
</div>
in blade.
<div x-data="myfunction()">
@livewire('posts')
</div>
<script>
window.livewire.on('gotcomment', () => {
console.log( '----')
this.callme() ; --> it goes error ..
});
function myfunction() {
return {
callme() {
console.log('callme')
},
}
}
</script>
this.callme() is not run..
How can I fire alpinejs function from livewire ?
Level 29
document.addEventListener('livewire:load', function () {
Livewire.on('gotcomment', (el, component) => {
@this.callme();
});
}
Please or to participate in this conversation.