【问题标题】:wire:change on select in livewire电线:在 livewire 中选择更改
【发布时间】:2021-11-08 13:32:08
【问题描述】:

当在下拉列表中选择一个选项时,我想在 livewire 中触发一个功能。但是使用 wire:click 或 wire:change dd 功能不起作用。在 livewire 中是否有一个 wire:bla bla 用于此?

<x-select name="course_id" label="{!! __('Ders') !!}" wire:model="course_id" wire:change="courseSelected" id="course_id"  :options="$this->courses"/>
 public function courseSelected(){
        dd("here");
}

【问题讨论】:

    标签: laravel laravel-livewire


    【解决方案1】:

    你应该挂钩到生命周期中更新的方法。

    https://laravel-livewire.com/docs/2.x/lifecycle-hooks

    public function updatedCourseId(){
       dd("here");
    }
    

    同时移除电线:更改

    【讨论】:

      【解决方案2】:

      如果你使用wire:model将元素绑定到属性,你可以像上面提到的那样挂钩生命周期

      public function updatedCourseId($value)
      {
          dd($value);
      }
      

      在另一种方法中,您可以使用 wire:change 监听事件,为此,您必须在监听器属性中定义事件,如

      <x-select label="{!! __('Ders') !!}" wire:change="$emit('courseSelected', $event.target.value)" id="course_id"  :options="$this->courses"/>
      
      // in component
      protected $listeners = [
         'courseSelected'
      ];
      
      public function courseSelected($value)
      {
         dd($value);
      }
      

      【讨论】:

        猜你喜欢
        • 2021-01-20
        • 2011-07-27
        • 2021-07-24
        • 2021-08-18
        • 2014-12-19
        • 1970-01-01
        • 1970-01-01
        • 2021-07-23
        • 2012-10-31
        相关资源
        最近更新 更多