Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request interceptor 能否支持异步 return config #1

Open
waynecz opened this issue Dec 10, 2018 · 0 comments
Open

Request interceptor 能否支持异步 return config #1

waynecz opened this issue Dec 10, 2018 · 0 comments

Comments

@waynecz
Copy link

waynecz commented Dec 10, 2018

当前版本

3.0.0

环境

  • 小程序内

需求描述

在小程序内有很多业务接口需要在登陆后在获取接口信息,那么是否可能在请求发起前先校验本地 token 是否存在,不存在直接挂起这个请求发情登录请求,等登录完成后,再将这个请求继续下去呢

示例:

http.interceptors.request.use(async config => {
  let token = wx.getStorageSync('token')

  if (!token) {
    // 没有登录的的情况下重新发起登录
    await store.dispatch('login')
  }

  token = wx.getStorageSync('token')
  config.headers.cookie = `token=${token}`
  return config
})

另外库非常好用,谢谢作者!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant