1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel Livewire JSで変数を書き換える

Posted at

Livewireを使っているとJSからPHP側の変数を書き換えたくなること多い
端的には

@this.set(変数,値);
でOK

admin/voyager/resources/views/test.php

<livewire:livewire_test> 

app/Http/Livewire/Livewire_test.php

?php

namespace App\Http\Livewire;

use Livewire\Component;

class Livewire_test extends Component
{
    public $setvalue;

    public function mount()
    {
        $this->setvalue=10;
    }
    public function render()
    {
        return view('livewire.livewire_test');
    }

}


resources/views/livewire/livewire_test.blade.php

{{$setvalue}}

<button onClick="@this.set('setvalue',100)"  >setvalueに100を入れる</button>

ドキュメントには$setってなってるけど、それだとうまく行かない・・
JS詳しくないからわからん・・

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?