1、state
就是實(shí)際存儲(chǔ)的變量
使用方法:
state:{
message: 'Hello!',
count:1
}
調(diào)用方法:
this.$store.state.message
2、getters
獲取數(shù)據(jù)的方法,相當(dāng)于vue里面的計(jì)算屬性
使用方法:
getters: {
message: state => state.message
}
調(diào)用方法:
this.$store.getters.message
3、Mutation
同步方法,用于更改狀態(tài)
使用方法:
mutations: {
increment(state) {
state.count++
}
},
調(diào)用方法:
store.commit(' increment')
4、actions
和mutation類似,不過支持異步操作,可以調(diào)用store.commit
使用方法:
actions: {
increment(commit) {
commit(' increment')
}
},