commit: 同步操作
this.$store.commit('方法名',值)【存儲】
this.$store.state.方法名【取值】
dispatch: 異步操作
this.$store.dispatch('方法名',值)【存儲】
this.$store.getters.方法名【取值】
當操作行為中含有異步操作,比如向后台發送請求獲取數據,就需要使用action的dispatch去完成了。
其他使用commit即可。
其他了解:commit=>mutations,用來觸發同步操作的方法。
dispatch =>actions,用來觸發異步操作的方法。在store中注冊了mutation和action,在組件中用dispatch調用action,然后action用commit調用mutation,