[Vuejs]-Adding to an existing object to make it reactive

0👍

I ended up puttting the part i wanted to be reactive into its own component and gave it a unique key.In my case it was a table and i aptly named my component <Table />and its not even a protected keyword to my surprise

<Table :key="componentKey" />

I then created this method

forceRerender() {
this.componentKey += 1;  
},

and accessed it when committing a mutation

.then( (response) => {
this.$store.commit('CRUD_CREATE_PROPERTY', response);
this.forceRerender();
})

also pay attention to the arrow function since this wouldn’t work on old style javascript functions,since nowadays arrow function is now vanilla javascript.

i give credit to Michael Thiessen’s article on Key-changing to force re-renders of a component which you can read here https://michaelnthiessen.com/force-re-render/

Leave a comment