0👍
So like I said in the comment: I use splice
and push
to get to the result I prefer.
When the user adds a dashboard, I send the settings for the dashboard to my API
and insert it in the db
. when the API
gives me a 200 http
, response I push the dashboard to the dashViews
array (using a vuex
mutation):
pushNewDashBoard(state, data) {
state.dashViews.push(data);
state.nodata = false;
}
When the user deletes a dashboard I also send the action to my backend API
. Again, when I get a 200 http
response I also delete the dashboard form the array like so (also using a vuex
mutation):
removeDashboard(state, id) {
let index = -1;
for (let i = 0; i < state.dashViews.length; ++i) {
if (state.dashViews[i].did === id) {
index = i;
break;
}
}
if (index > -1) {
state.dashViews.splice(index, 1);
}
}
The above mentioned methods save me form re-building the whole dashViews
every time a user deletes or adds a dashboard.
Source:stackexchange.com