【问题标题】:How to pass data to livewire modal component?如何将数据传递给 livewire 模态组件?
【发布时间】:2022-01-16 15:09:46
【问题描述】:

我有如下添加按钮的类别组件。

<button wire:click.prevent="addNew" class="btn btn-primary mb-2">Add</button>
  .....
  .....
<x-mymodal-component :iscreate="$iscreate"/>

使用 'addNew' 方法,我将事件分派给 javascript 监听器。

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

在侦听器事件中,我尝试显示作为组件制作的模态。

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

下面是模态组件,需要传入的数据。

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

非常感谢您对此提供任何建议或指导,谢谢。

【问题讨论】:

    标签: laravel laravel-livewire


    【解决方案1】:
    @livewire('mymodal-component', ['iscreate'=>$iscreate])
    
    //Receive:
     public function mount($iscreate)
      {
    
      }
    

    【讨论】:

      猜你喜欢
      • 2020-12-14
      • 2016-01-13
      • 2017-06-15
      • 2021-09-02
      • 1970-01-01
      • 2019-12-17
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多