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 }




  • 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