This repository was archived by the owner on May 12, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ const h = eventBus.$createElement.bind(eventBus)
1010 * @description 创建一个 axios 基础请求实例,提示,环境变量可在 .env.[mode] files 中定义
1111 * @param {String } baseURL 基础请求路径
1212 */
13- export default function createBaseRequest ( baseURL ) {
13+ export default function createRequest ( { baseURL, headers , auth = false } ) {
1414 if ( ! baseURL ) throw new Error ( '[createRequestBase]: Wrong baseURL type !' )
1515
1616 const request = axios . create ( {
@@ -20,12 +20,12 @@ export default function createBaseRequest(baseURL) {
2020
2121 request . interceptors . request . use (
2222 req => {
23- req . headers [ 'content-type' ] = 'application/json'
24- req . headers [ 'app_key' ] = process . env . VUE_APP_KEY
25- req . headers [ 'app_secret' ] = process . env . VUE_APP_SECRET
23+ req . headers [ 'Content-Type' ] = 'application/json'
2624
27- const token = tokenInCookie . getItem ( )
28- if ( token ) req . headers [ 'access_token' ] = token
25+ const token = tokenInCookie . getItem ( ) || 'simulator'
26+ if ( token && auth ) req . headers [ 'Authorization' ] = `Bearer ` + token
27+
28+ if ( headers ) Object . assign ( req . headers , headers )
2929
3030 return req
3131 } ,
You can’t perform that action at this time.
0 commit comments