Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

javascript - On pushing object in array the vue ui is not getting updated

I am stucked in a problem where I have created a custom drag drop component which is working fine,

there is an array which is connected to vuex store, i have created the mutations to update or add new object inside the array that array is getting changed after drop operation but the ui is not getting changed

I am fetching that array using this.$store.getters['moduleName/functionName']

mutation.js=>

   export default {
       setNewValue(state, payload){
           state.arr.push(payload);
       }
   }

handleDrop function =>

handleDrop(event, data){
     let actionType = this.$store.getters["moduleName/getActionType"];
     let obj;
     let length = this.$store.getters["moduleName/getLengthOfArr"];
        obj = {
          id: length == 0 ? 1 : length + 1,
          name: data.name,
          isConditional: false,
          ...actionType[data.type],
          yes: [],
          no: [],
        };
        this.$store.commit("moduleName/setNewValue", obj);

action Type are some objects which i need to add based on data type provided

i guess it is due to reactivity of object properties or due to computed property which i am using in ui

computed : {
     arr(){
         return this.$store.getters['moduleName/getArray'];
     }
}

getters.js

export default {
    getArray(state){
         return state.arr;
    }
}

Thanks in advance

question from:https://stackoverflow.com/questions/65932567/on-pushing-object-in-array-the-vue-ui-is-not-getting-updated

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After some debugging i solved the problem as the problem was with rendering the data was getting updated and even store was getting updated

while rendering i was using the same object which was rendered previously but that made me so much confused due to vuejs' reactivity with computed property.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...