[Vuejs]-Vuex: Trying to run a block of code in a Getter

0👍

The issue is you’re using an implicit global x where you should define it locally.

You should also define arr outside the if block.

getVipCustomersKeys(state) {
  const arr = [] // define "arr" before the "if"
  if (state.vipCustomers) {
    for (let x in state.vipCustomers) { // define "x" locally
      arr.push(x);
    }
  }
  return arr;
},

Even better, just use Object.keys() to return all the keys from state.vipCustomers

getVipCustomersKeys: ({ vipCustomers }) => Object.keys(vipCustomers ?? {})

Leave a comment