Can't access state through mutation in VUEX?



  • I am following the suggested store file structure. Inside mutations.js I have :
    export function UPDATE_PAID_MONTHLY_EXPENSES(state , key){
    //state.paidMonthlyExpenses = […state.paidMonthlyExpenses, key]
    I am trying to add an item to an array like in above commented code. but It doesn’t work. So I tried console logging the state from inside this function and the state is an {__ ob __: Observer} object . I can see the state as an object in devTools if I expand the object, but I can’t access anything from it, if I try to, it still counts as another { __ ob __: Observer}. Can someone help me fix this.
    }

    I also think that the the state, might actually be a module, so thats why you can have state.state, but I even tried that, but it still gives me { __ ob __ : Observer }

    0_1551664391108_ec1a81f2-1b84-4c1b-9beb-47eeead62038-image.png

    0_1551664435322_526d4eac-9a5e-4ce4-9b30-f34b6160b06a-image.png

    0_1551664470593_05676732-9ecd-4799-8d37-c30a40d75321-image.png



  • Your state is similar to

    const state = {
      state: {
        paidMonthlyExpenses: []
      }
    }
    

    You should set it like (two times “state”)

    state.state.paidMonthlyExpenses = [...state.state.paidMonthlyExpenses, key]
    


  • @morlz You deserve a truck load of beer ❤ . Thanks a lot for helping me out I appreciate it.


Log in to reply