Livewire multiple wire:click, first one works, rest do not

前端 未结 2 1515
遥遥无期
遥遥无期 2021-01-27 08:21

I am putting together a CRUD app using livewire and my issue is with wire:click on the different buttons. I have a create modal come up and the wire:click in that modal works pe

相关标签:
2条回答
  • 2021-01-27 08:39

    To not confuse Livewire, you should use wire:key on elements in a loop. This also means that you should wrap you HTML in one parent <div>.

    @foreach ($items as $org)
        <div wire:key="{{ $loop->index }}">
            <button class="btn btn-sm btn-success" wire:target="edit('{{$org->id}}')">Edit</button>
            <button class="btn btn-sm btn-danger" wire:click="delete({{$org->id}})">Delete</button>
        </div>
    @endforeach
    
    • https://laravel-livewire.com/docs/2.x/troubleshooting
    0 讨论(0)
  • 2021-01-27 09:04

    Livewire uses a complex DOM diffing algorithm to intelligently swap components. So When you have loops make sure to add keys and wrap them in a parent container.

    <div wire:key="{{$org->id}}">
            <button class="btn btn-sm btn-success" wire:target="edit('{{$org->id}}')">Edit</button>
            <button class="btn btn-sm btn-danger" wire:click="delete({{$org->id}})">Delete</button>
    </div>
    
    0 讨论(0)
提交回复
热议问题