我有一個刪除路由 Inertia.js,這樣當我刪除一個項目時,它會重定向回我所在的頁面。但是,這並不是在 Inertia destroy 路由中呼叫 onSuccess() 函數。
範例.vue
deleteSubmit(id) { this.accountsDataTable.destroy(); Inertia.destroy(route('installers.destroy', {id: id}), {}, { preserveState: true, onSuccess: () => { this.accountsDataTable = $('#table').DataTable({ columnDefs: [{ target: 1 }] }); } }) },
ExampleController.php
//Validate the request //Create the installer //Redirect back on success return redirect()->route('installers.index')->with('success', 'Installer was successfully deleted.');
但是,資料表沒有按照我想要的方式重新建立。這是之前的樣子:
正確的圖片
之後的情況是這樣的:
圖片錯誤
我嘗試將控制器程式碼更改為:
return redirect()->back()->with('success', 'Installer was successfully deleted');
但是資料表仍然沒有以應有的方式顯示。
1:在控制器中使用訊息資料設定重定向。
2: HandleInertiaRequests 中間件。
3:在元件中。
文檔:https://inertiajs.com/shared-data