vue-typescript-admin-template
vue-typescript-admin-template copied to clipboard
Vuex mutation req to api returns undefined
I am replicating this approach in my personal repository but seem to be getting an error when I try to return data from an axios request. Based on your code, data
should contain the response.data
that comes from the api hit.
For me, within service.interceptors.response
the response.data
is a object that has data but by the time it reaches await login
, that data is undefined.
I am just curious how did you get this to work?
@Action
public async Login(userInfo: { username: string, password: string}) {
let { username, password } = userInfo
username = username.trim()
const { data } = await login({ username, password })
setToken(data.accessToken)
this.SET_TOKEN(data.accessToken)
}
export const login = (data: any) =>
request({
url: '/users/login',
method: 'post',
data
})
probably a better question is - why aren't you using return request
?
I have the same question. Did anyone configured out?