Answers for "livewire events"

1

livewire event

inside livewire controller
$this->emit('eventName');

inside livewire blade file
<script type="text/javascript">
    window.onload = function() {
        Livewire.on('eventName', () => {
           // Code Here
        })
    }
</script>
Posted by: Guest on January-22-2021
1

livewire events

Firing Events:

From The Template

    <button wire:click="$emit('postAdded')">


From The Component

   $this->emit('postAdded');


From Global JavaScript

    <script>
        Livewire.emit('postAdded')
    </script>
    
    
    
Event Listener:

    class ShowPosts extends Component
    {
        public $postCount;

        protected $listeners = ['postAdded' => 'incrementPostCount'];

        public function incrementPostCount()
        {
            $this->postCount = Post::count();
        }
    }
Posted by: Guest on June-22-2021

Browse Popular Code Answers by Language