vue-typescript-admin-template icon indicating copy to clipboard operation
vue-typescript-admin-template copied to clipboard

Vuex mutation req to api returns undefined

Open rostgoat opened this issue 4 years ago • 2 comments

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
  })

rostgoat avatar Mar 03 '20 23:03 rostgoat

probably a better question is - why aren't you using return request ?

rostgoat avatar Mar 03 '20 23:03 rostgoat

I have the same question. Did anyone configured out?

hsweif avatar Dec 15 '20 04:12 hsweif