总的来说他们只是存取方式的不同,两个方法都是传值给vuex的mutation改变state
commit: 同步操作
存储
this.$store.commit('changeValue',name)
取值
this.$store.state.changeValue
dispatch: 异步操作
存储
this.$store.dispatch('getlists',name)
取值
this.$store.getters.getlists
使用例子
this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
this.$router.push({ path: '/' }); //登录成功之后重定向到首页
}).catch(err => {
this.$message.error(err); //登录失败提示错误
});