A
A
Apostol632021-02-04 10:57:57
Vue.js
Apostol63, 2021-02-04 10:57:57

How to write to state by composite key?

Good day to all.

I have three states

export const state = () => ({
  credit: {},
  price: {},
  benefit: {},
});


There is also a mutation that takes a type as one of its parameters.
setByCode(state, data) {
    let params = {
        'data': 'test'
    };
    set(state + '.' + data.type, data.code, params);
  },


set method from lodash
I decided to use state + '.' + data.type so that, depending on the type, it is written to the required state.

The problem is that the first parameter of set must be an object, but I get a string and nothing is written to the state

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Red_Devi1, 2021-02-04
@Apostol63

state[data.type]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question