riomigal
1 week ago

How to execute function in app.js from a livewire component with alpine.js?

Posted 1 week ago by riomigal

Hello,

I am trying to access functions in app.js from a livewire component with alpine.js "x-init".

For testing purposes I have this function in my app.js:

const sayHello = () => { alert('hello'); }

And in the livewire component:

I get this error: alpine.js:1834 Uncaught ReferenceError: sayHello is not defined

Sry, I am new in Javascript, how can I define the function before it is invoked?

Thank you!

Please sign in or create an account to participate in this conversation.