Skip to content

Commit

Permalink
Action2
Browse files Browse the repository at this point in the history
  • Loading branch information
malagege committed Jun 24, 2021
1 parent 637dfc3 commit c0de63b
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/main.js
Expand Up @@ -9,13 +9,17 @@ const store = createStore({
count: 0
},
mutations: {
increment (state) {
state.count++
increment (state,{amount}) {
state.count += amount
}
},
actions: {
increment (context) {
context.commit('increment')
incrementAsync ({ commit, state },payload) {
console.log('payload',payload)
setTimeout(() => {
commit('increment',payload)
console.log('count result:' + state.count )
}, 1000)
}
}
})
Expand All @@ -27,9 +31,22 @@ const store = createStore({
createApp(App).use(store).mount('#app')


console.log(`舊值:${store.state.count}`);
console.log(`舊值:${store.state.count}`)

store.dispatch('increment')
store.dispatch('incrementAsync', {
amount: 10
})

// await store.dispatch('setNum')
console.log(`新值:${store.state.count}`)

console.log('-----------')

console.log(`舊值:${store.state.count}`)

store.dispatch('incrementAsync', {
amount: 10
})

// await store.dispatch('setNum');
console.log(`新值:${store.state.count}`);
console.log(`新值:${store.state.count}`)

0 comments on commit c0de63b

Please sign in to comment.