There is such a scene that I encountered while writing today
I wrote a router-to in the component to jump to a component and passed a name to that component. This name is in the route. Define and pass it to the jump component using the beforeEnter method
The jump component uses prop to get the name
Then I have a problem: I get the name, and now I judge the data of the name
Then methods in the component Define a method goodorbad
if (name === 'zhangsan') {
return 'good'
} else {
return 'bad'
}
Then I want to write this method into mutation in vuex now,
I will write one
export const goodorbad (state, items) {
if (items.name === 'zhangsan') {
return 'good'
} else {
return 'bad'
}
}
Then I write
in the jump to component...mapmutaion([
'goodorbad'
])
ps () {
let items = {
name: this.name
}
this.goodorbad(items)
}
The return cannot be obtained in this way, I think why.
迷茫2017-06-12 09:26:42
Go and take a good look at the official documentation of vuex
The only way to change the state in the Vuex store is to submit a mutation. Mutations in Vuex are very similar to events: each mutation has a string event type (type) and a callback function (handler). This callback function is where we actually make the state changes, and it accepts state as the first parameter: