Home > Blockchain >  How to pass data to livewire modal component?
How to pass data to livewire modal component?

Time:12-13

I have category component with add button as below.

<button wire:click.prevent="addNew" >Add</button>
  .....
  .....
<x-mymodal-component :iscreate="$iscreate"/>

with 'addNew' method, I dispatch event to javascript listener.

public function addNew(){
    $this->dispatchBrowserEvent('show-category-modal');
}

In the listener event, I try to show modal that made as component.

  window.addEventListener('show-category-modal', event => {
    $('#category-form').modal('show');
  });

Below is modal component with data that need to pass into.

<x-mymodal-component :iscreate="$iscreate"/>

Any advice or guidance on this would be greatly appreciated, Thanks.

CodePudding user response:

@livewire('mymodal-component', ['iscreate'=>$iscreate])

//Receive:
 public function mount($iscreate)
  {

  }
  • Related