Vuex: Doesn't change value of state by argument destructuring on mutations.

Created on 3 Jan 2017  路  3Comments  路  Source: vuejs/vuex

demo

const store = new Vuex.Store({
  state: {
    text: 'hello'
  },
  mutations: {
    // don't work
    dontWork({text}, payload) {
      text = payload
    },
    // work
    work(state, payload) {
      state.text = payload
    }
  }
})

I can't use es6 argument destructuring on mutations?

Most helpful comment

Assuming state.text is a string, the reason this doesn't work is because primitive types are passed by value in javascript. It would be the same as doing

```
let text = state.text;
text = payload; // state.text still has its old value

All 3 comments

Assuming state.text is a string, the reason this doesn't work is because primitive types are passed by value in javascript. It would be the same as doing

```
let text = state.text;
text = payload; // state.text still has its old value

^ What @BartCorremans said.

Thank you. i got it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gorbypark picture gorbypark  路  3Comments

niallobrien picture niallobrien  路  3Comments

blocka picture blocka  路  4Comments

jbruni picture jbruni  路  3Comments

ktsn picture ktsn  路  4Comments