下面是我的actions.js中的方法
export const parseToken = ({dispatch}, token) => {
return Vue.http
.post(config.dev.host + '/api/parseToken', {
token
})
.then((res) => {
console.log(res)
if (res.body.status == 0) {
dispatch('SET_USERNAME', res.body.username)
}
return res
}, (err) => {
console.log(err)
})
.catch((err) => {
console.log(`catch ${err}`)
})
}
我是在main.js进行调用,已经引入store, parseToken
parseToken(store.state, access_token)
下面是请求返回结果,res输出内容
然后catch到了error
catch TypeError: dispatch is not a function
希望大家可以帮忙解决下。。。
dispatch方法在stroe上,而不是在store.state上
改成
https://jsfiddle.net/ycloud/6...