Im using Laravel + Inertiajs (Vue). Im rendering a page with a Prop. "organizations".
public function index()
{
$this->access();
$companyOrganisations = $this->user->companyUser->company->organisations;
return Inertia::render('CompanySettings/CompanyOrganisations', [
'organisations' => $companyOrganisations,
]);
}
Index View:
<!-- Existing Organisations -->
<div class="col"
v-for="(organisation, index) in organisations"
:key="organisation.id"
:ref="organisations">
<!-- Code -->
</div>
<Link class="link-success"
href="#"
@click.prevent="createOrganisation()">
<i class="fa fa-check-square-o p-1"></i>
</Link>
Vue.js: createOrganization()
export default {
components: {
Card,
Textarea,
Link,
},
props: [
'organisations',
],
data: function () {
return {
manageOrganisations: [],
newOrganisation: {
name: '',
description: '',
}
}
},
methods: {
createOrganisation() {
axios.post('company-organisations-create', {
name: this.newOrganisation.name,
description: this.newOrganisation.description
})
.then((response) => {
// Add Organisation to DOM
this.organisations.push(response.data.newOrganisation);
console.log(this.organisations); // <-- New Organization added is fine
}).catch((error) => {
window.Toast.error(error.message);
});
},
// Other Code
}
}
So, after I sent the new Organization-Data to Server & Database, I receive the new Object newOrganisation from Server as json, which I push to this.organisations. This works fine so far. And I see the new Organization has been added in DOM (v-for loop), for a milisecond. Until, a little partial refresh happens and the new Organization is lost again - cauz it goes Back to old values (from index rendering).
How can I keep the new Value & stop refreshing the prop. by the old Value? Or what Am I doing wrong?
Thanks alot!
organisationsgoing forward), or you could do a partial reload.