A
A
alaskafx2021-11-19 20:05:45
Vue.js
alaskafx, 2021-11-19 20:05:45

Valid display issue with v-for + vuex?

There is a storage in which data can change at any time:

storage:

cars: [
                {
                    name: 'Debian',
                },
                {
                  name: 'Ss'
                },
                {
                   name: 'Gorsto'
                },
            ],


mutation:
deleteCarFromArray: (state, payload) => {
           state.cars[payload] = {InfoCreate: -1}
        },


getter:
carInfoGetter(store){
            return [...store.cars]
        }


In component:

computer:

filteredCards() {
      return this.$store.getters.carInfoGetter.filter((el) => {
        return el.InfoCreate !== -1 && el.InfoCreate !== -2;
      });


The cards themselves:

<div  v-for="(card, index) in filteredCards" :key="index.id">
...
</div>


The essence of the problem is that if some action occurs (mutation is called) - cards that do not change on the page in any way.
Cards that are NOT returned by the filteredCards filter should not appear, but now they remain in place and do not change in any way with some kind of mutation.
How to decide and why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-11-19
@Aetae

Vue 2 doesn't know how to listen for array changes by index. You either need to use array.splice or Vue.set .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question