The prop does not update after inertia.post
See original GitHub issueVersions:
@inertiajs/inertia
version: 0.8.2@inertiajs/inertia-vue3
version: 0.3.4
Describe the problem:
For testing proposes I have develop a simple testing case, I cannot get it working to refresh data after “Submit” button pressed. I am using Laravel 8 + InertiaJS + Vue3.
Very simple and but still I cannot make it refresh the prop ‘documents’ after hitting Test button as a simulation of a form submit.
In the Controller I have write for testing purpose date(‘H:i;s’), because if I access the url on the browser, i have current time with seconds included.
If I hit refresh on browser, the date is updated but if I hit Test button it makes the network request for POST /manufacturers/save, then I can see in the network the GET for /manufacturers, which contains updated date but on the front it will not update.
What I am doing wrong?
Steps to reproduce:
This is the web.php:
<?php
use App\Http\Controllers\Catalog\ManufacturersController;
use App\Http\Controllers\DashboardController;
use Illuminate\Support\Facades\Route;
Route::get('/', [ DashboardController::class, 'index']);
Route::prefix('catalog')->group(function () {
Route::get('manufacturers', [ManufacturersController::class, 'index']);
Route::post('manufacturers/save', [ManufacturersController::class, 'save']);
}
);
This is the controller:
<?php namespace App\Http\Controllers\Catalog;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
class ManufacturersController extends Controller
{
public function index()
{
return Inertia::render('Catalog/Manufacturers/Index', [
'documents' => [
['name' => 'Timestamp ' . date('H:i:s')],
]
]);
}
public function save()
{
return redirect()->back();
}
}
This is the component:
<template>
<div>
<div v-for="(name, index) in documents" :key="index">{{ name }}</div>
<el-button @click="save()">Test</el-button>
</div>
</template>
<script>
import Layout from "../../../Common/Layout";
export default {
layout: Layout,
props: ['documents'],
data() {
return {
}
},
methods: {
save() {
this.$inertia.post('/catalog/manufacturers/save');
}
}
}
</script>
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
Okay it was a reactivity issue
I was using it like
And obviously I needed to use a computed property, got mislead by the fact
$props
was already a computed property, but it doesn’t matter because I’m accessing a value in that computed propertyI figured out how this is meant to be used. @ape-les Was on the right track with the link they posted. The data I was targeting doesn’t appear to be used, reactively. I’m avoiding page reloads, altogether. So, I needed to store a static object with my flash messages and then listen to the
navigate
event on$inertia
to grab the data from said event. When I change it on a reactive piece of data, I achieve what I need.I hope this write-up helps anyone else who might be struggling with this.