Livewire JavaScript で emitSelf、emitUp のやり方

ショコラ
ショコラ

Livewire JavaScript で emitSelf、emitUp のやり方

↓下のリファレンスには、Livewire.emit、Livewire.emitTo の記載はあるのに、Livewire.emitSelf、Livewire.emitUp については記載されていません。
https://laravel-livewire.com/docs/2.x/reference#global-livewire-js
ひとまず、emitSelf、emitUp のやり方は「@this.emitSelf(‘foo’, …args)」、「@this.emitUp(‘foo’, …args)」とやります。因みに「@this」は「”window.livewire.find(‘{{ \$_instance->id }}’)”」です。
↓下のソースを参照しました。
vendor/livewire/livewire/js/component/index.js

もっさん先輩
もっさん先輩

wire:click で自身のアクションメソッドを実行できます。

<button type="button" wire:click="debug()">debug</button>

↑上は↓下のように @this.debug と書くことができます。

<button type="button" onClick="@this.debug()">debug</button>

JavaScript で自身へイベントを送るには「@this.emitSelf」と書きます。

<button type="button" onClick="@this.emitSelf('debug',Livewire.data())">debug</button>

JavaScript で親へイベントを送るには「@this.emitUp」と書きます。

<button type="button" onClick="Livewire.emitParent('debug',Livewire.data())">debug</button>

以上

Scroll to Top