简体   繁体   English

在数组中推送 object 时,vue ui 没有得到更新

[英]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有一个连接到 vuex 存储的数组,我创建了突变以更新或添加新的 object 在数组中,该数组在删除操作后发生更改,但 ui 没有更改

I am fetching that array using this.$store.getters['moduleName/functionName']我正在使用this.$store.getters['moduleName/functionName']获取该数组

mutation.js =>突变.js =>

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

handleDrop function => 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我猜这是由于 object 属性的反应性或由于我在 ui 中使用的计算属性

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

getters.js getters.js

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

Thanks in advance提前致谢

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.在渲染时,我使用的是之前渲染的相同 object,但由于 vuejs 对计算属性的反应性,这让我非常困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM