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

Axios #53

Open
into-piece opened this issue May 19, 2021 · 2 comments
Open

Axios #53

into-piece opened this issue May 19, 2021 · 2 comments

Comments

@into-piece
Copy link
Owner

  1. Axios 如何缓存请求数据?
  2. 如何取消请求
  3. 拦截器interceptors 实现 token携带认证信息
@into-piece
Copy link
Owner Author

取消请求

cancelToken 底部原理是xmlHttpRequest 的abort

@into-piece
Copy link
Owner Author

into-piece commented May 19, 2021

interceptors

拦截器有对应request和response的设置,request设置发起的请求统一加上token的自定义header

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  config.headers.token = 'added by interceptor';
  return config;
});

// 添加响应拦截器
axios.interceptors.response.use(function (data) {
  data.data = data.data + ' - modified by interceptor';
  return data;
});

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