axios设置请求头中的Authorization 和 cookie 信息:

GET请求

axios.get(urlString, 
  {
    headers: {
      'Authorization': 'Bearer ' + token,
      "Cookie" : 'sessionId=' + sessionId + '; recId=' + recId,
      ...
    },
    params: {
      param1: string,
      param2: string
    },
    ...
  }
)
.then(res => fn)
.catch(e => fn)

POST请求

axios.post(urlString, 
  {
    data: data,
    ...
  },
  {
    headers: {
      'Authorization': 'Bearer ' + token,
      "Cookie" : 'sessionId=' + sessionId + '; recId=' + recId,
      ...
    }
  }
)
.then(res => fn)
.catch(e => fn)

miomiomio
147 声望5 粉丝

人生昧履,砥砺而行