[Vuejs]-Getter returning same value as the input value before action finish in Vue

1๐Ÿ‘

โœ…

my guess is your issue lies here:


TL;DR โ€“ you pass your getter as valor to your action.


only a guess โ€“ as i cant debug your code


        store.dispatch('profundidadeSondagem/MODIFY', patologia).catch(() => {

            this.valorProfundidade = this.profundidadeSondagem;
        })

as you assign a reference from your rootState[...] and thus you change the properties of the rootState[...] in your component past the first run.

So your code then behaves like:

        let patologia = {
            arcada: this.arcada,
            sextante: this.sextante,
            dente: "dente_" + this.dente,
            face: this.face_json,
            
          // valor: this.valorProfundidade,
          ///* same as */ valor: this.profundidadeSondagem,
          /* same as */ valor: this.$store.getters['profundidadeSondagem/profundidadeSondagem'](...),
            modelRefs: modelRefs,
            id: this.changedId,
            valorInserido: this.valorInserido,
        };

A solution can be to this.valorProfundidade = this.profundidadeSondagem.slice(); as long it is an array or Object.assign({},...) โ€“ so you prevent the references

๐Ÿ‘คEstradiaz

Leave a comment