I decided to give Volt a try today and basically copy/pasted the example from their documentation with the counter and it does not work. I used the functional API and the class based API and still no luck. When I use it the Livewire way (separate files for the php and blade) without Volt it works. I would appreciate. This is what I have tried literally from documentation. I have put some ray() logging in the increment method and nothing is happening. I did php artisan volt:install before that.
Any ideas why it is not working?
<?php
use Livewire\Volt\Component;
new class extends Component {
public $count = 0;
public function increment()
{
$this->count++;
}
} ?>
<div>
<h1>{{ $count }}</h1>
<button wire:click="increment">+</button>
</div>
How are you using the component? Using <livewire:counter /> or as an anonymous component?
You also need to make sure you have the full HTML document when loading a Livewire v3 component so Livewire can inject its JavaScript. Here are two examples, one using the regular Livewire and the latter with an anonymous component:
Thanks @thinkverse! I was using it with Folio by creating pages/volt.blade.php and using only livewire:counter/ component there. By the way I have views/components/layouts/app.blade.php from invoking php artisan livewire:layout but I guess this folio page does not use this layout and thats why it is not working.
Once I added the full HTML document it works. I guess I need to see how to use layouts with Folio pages