use pure javascript in livewire
hello,
i create a simple javascript timer in blade view
How can call method inside the script?
i tryed with {{ $this->method() }} but not work
23 Replies
How can call method inside the script?In what script?
setTime()
from javascript
If you want to "start" that from JS, I think there is a $this->js()
or similar methodyes in setTime method, but need to call livewire action
Ah, you want to call Livewire from JS. That should be
$wire.yourMethod()
if you are inside a LW componentI'm inside custom page, I tried like this but if I try to use @script and @endscript by embedding the javascript code it gives me an error
can't I use pure javascript code?
It's an Alpine error so where are you using this inside Alpine? You just showed in in
<script>
tags?not use alpine but pure js
But you error says
Alpine Expression Error
so it looks like you are using this somewhere inside Alpine?
Where are you using that code?look screenshot
the script is inside a blade view
blade view linked to custom page
Could it be that within the @script tags I can only use alpine code?
Can you share the whole page? Maybe as a Gist if it gets to big?
yes wait
view_page.php
blade view
I would use alpine
https://codepen.io/KevinBatdorf/pen/xxVVoaX?editors=1010
ok try this
Hm. The Blade file looks good to me 🤔
yes the file is ok and the script work...but I wanted to use wire call inside js. just for code cleanup
i use this script but count go down by 2 at time... 20 18 16 14 every one second
i tryed with this.count-- and --this.count with same result 🤬
ok fixed...remove x-init="init()"
Solution
working script
much better than JS 👌