Skip to content

Commit

Permalink
mutation 5
Browse files Browse the repository at this point in the history
  • Loading branch information
malagege committed Jun 23, 2021
1 parent caa624c commit 00841e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/main.js
@@ -1,16 +1,15 @@
import { createApp } from 'vue'
import { createStore } from 'vuex'
import App from './App.vue'
import { SOME_MUTATION } from './mutation-types'

// 創建一個新的 store 實例
const store = createStore({
state: {
count: 1
},
state: { count:0 },
mutations: {
increment (state, payload) {
// 变更状态
state.count += payload.amount
// 我們可以使用 ES2015 風格的計算屬性命名功能來使用一個常量作為函數名
[SOME_MUTATION] (state) {
state.count += 1
}
}
})
Expand All @@ -22,8 +21,7 @@ createApp(App).use(store).mount('#app')


store.commit({
type: 'increment',
amount: 10
type: SOME_MUTATION
})

console.log('store.state.count:' + store.state.count)
2 changes: 2 additions & 0 deletions src/mutation-types.js
@@ -0,0 +1,2 @@
// mutation-types.js
export const SOME_MUTATION = 'SOME_MUTATION'

0 comments on commit 00841e0

Please sign in to comment.