mirror of
https://github.com/zuiidea/antd-admin.git
synced 2024-04-21 12:32:14 +00:00
add doc about custom http header #829
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
- Getting started
|
||||
- [Quick Start](getting-started.md)
|
||||
- Customization
|
||||
- [Request](request.md)
|
||||
- [Configuration](configuration.md)
|
||||
- Guide
|
||||
- [Deploy](deploy.md)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# HTTP request
|
||||
|
||||
this project use axios for http service, file located in src/utils/request.js
|
||||
|
||||
## Custom Header
|
||||
|
||||
As for privilege access or modify cookie, you could add header param by yourself
|
||||
|
||||
```
|
||||
axios.defaults.headers.common['Authorization'] = 'token'
|
||||
```
|
||||
|
||||
Or
|
||||
|
||||
```
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.token = window.localStorage.getItem('token');
|
||||
return config;
|
||||
}, function (error) {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
```
|
||||
@@ -1,6 +1,7 @@
|
||||
- 入门
|
||||
- [快速上手](zh-cn/getting-started.md)
|
||||
- 定制化
|
||||
- [http请求](zh-cn/request.md)
|
||||
- [配置项](zh-cn/configuration.md)
|
||||
- 指南
|
||||
- [部署](zh-cn/deploy.md)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# HTTP请求
|
||||
|
||||
本项目使用了axios提供http请求服务,文件在src/utils/request.js
|
||||
|
||||
## 自定义Header
|
||||
|
||||
为了提供鉴权、修改cookie等服务,可以手动修改Header
|
||||
|
||||
```
|
||||
axios.defaults.headers.common['Authorization'] = 'token'
|
||||
```
|
||||
|
||||
或者
|
||||
|
||||
```
|
||||
// 添加请求拦截器
|
||||
axios.interceptors.request.use(function (config) {
|
||||
// 在发送请求之前做些什么
|
||||
config.headers.token = window.localStorage.getItem('token');
|
||||
return config;
|
||||
}, function (error) {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
```
|
||||
Reference in New Issue
Block a user