[英]Force a full page reload in Livewire
我將Livewire和Alpine與Laravel 8一起使用。
我有一個帶有數據表(jQuery)和引導模式的頁面。
該表填充了來自 model 實例列表的一些數據。
當我單擊表中的按鈕時,它會打開模式並允許編輯相應的記錄。
這部分按預期工作。
然而, Datatable庫更難與 Livewire 一起使用,所以我決定將整個Datatable scope 放在帶有wire:ignore
屬性的<div>
中。
因此,如果我想在進行修改后刷新Datatable ,我不能使用魔術$refresh
因為Datatable當前的范圍在wire:ignore
內。
所以我正在考慮在編輯完成后重新加載整個頁面,但我不知道如何做到這一點, return redirect()->back()
不起作用......
這就是我的save
方法的樣子,當從模式編輯完成時調用它:
public function save()
{
MyModel::where('id', $this->edited_id)->update([...]);
$this->clearSelection();
return redirect()->back(); // This is not working
}
這是我的桌子:
<div wire:ignore>
<table class="dt-table table">
<thead>
<tr>
<th>Actions</th>
<th>id</th>
<th>name</th>
<th>other</th>
</tr>
</thead>
<tbody>
@foreach ($models as $m)
<tr>
<td>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#mymodal">Edit</button>
</td>
<td>{{ $m->id }}</td>
<td>{{ $m->name }}</td>
<td>{{ $m->somedata }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
檢查您使用的是 Livewire 2.xx 版,您應該能夠按照此處的文檔進行操作:
https://laravel-livewire.com/docs/2.x/redirecting
火線組件:
class ContactForm extends Component
{
public $email;
public function addContact()
{
Contact::create(['email' => $this->email]);
return redirect()->to('/contact-form-success');
}
}
Livewire 組件模板
<div>
Email: <input wire:model="email">
<button wire:click="addContact">Submit</button>
</div>
Livewire 將原始 URL 存儲在Referer
標頭中。 您可以使用它來刷新頁面:
return redirect(request()->header('Referer'));
在包含貨幣組件的視圖中
@livewire('nav-cart',['page'=>request()->fullUrl()])
然后在組件中,安裝方法
public function mount($page)
{
$this->page = $page;
創建一個公共屬性$page,然后在更改貨幣之后
return redirect($this->page);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.