Answer the question
In order to leave comments, you need to log in
Why does the vuex state array of objects in the state store increase by one array element instead of being overwritten?
I accept json from the server. in the b-table component (bootstrap-vue), which renders the elements as rows from the items
array
Instead of overwriting the array with root objects in storage every time, it adds it as another array element with nested objects, and another, and another .. and more .. and so on. every time you switch.
It is necessary that it be <b>items</b>[{one}, {two}, {three}]
And he, under all equal conditions, does
<b>items</b>[
[{one}, {two}, {three}],
[{one}, {two}, {three}],
[{one}, {two}, {three}]
]
<b-table striped="striped" bordered="bordered" responsive="sm"
:items="items" :fields="fields" :current-page="currentPage" :per-page="perPage">
mounted() {
this.$store.dispatch('settings/fetchSysTax');
},
computed: {
items: {
get() {
return this.$store.state.settings.systaxs;
},
},
},
export const fetchSysTax = ({ commit }) => new Promise((resolve, reject) => {
Vue.$http.get('/taxs').then((response) => {
commit(types.FETCH_SYSTAX, response.data);
resolve(response);
}, (err) => {
reject(err);
});
});
[FETCH_SYSTAX](state, fetchSysTax) {
state.systaxs = fetchSysTax; <-- данные ввиде json
// Vue.set(state.systaxs, fetchSysTax); <-- так тоже самое
// fetchSysTax.forEach((itm) => { <-- и так тоже самое
// state.systaxs.push(itm); <-- и так тоже самое
// });
},
[{"id":1,"name":"asdasd","title":"stand2","perc":34},{"id":2,"name":"213123","title":"213123","perc":1231},{"id":3,"name":"asdasd","title":"asdasd","perc":1011},{"id":4,"name":"qwe","title":"qwe","perc":11},{"id":6,"name":"werwer","title":"werwer","perc":23}]
export default {
systaxs: [],
};
mounted() {
this.$store.dispatch('settings/fetchSysTax')
.then((value) => {
this.items = value.data;
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question