javascript - Regarding the problem of mutation in vuex, I am very anxious while waiting online. Can you give me a hint?
为情所困
为情所困 2017-06-12 09:24:42
0
1
694

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.

为情所困
为情所困

reply all (1)
迷茫

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:

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!