使用Axios设置请求头(headers)
get请求
axios.get(url, config)
.then(res=> console.log(res))
.catch(err=> console.log(err))
举例:
axios.get('/manger/getAllStudentInfo', {
headers: {
Authorization: `Bearer ${sessionStorage.getItem("token")}`
}
}).then(
(response) => {
if (response.data.code == 0) {
let dataList = response.data.data.information
dataList.map((item) => {
return item.key = item.student_id
})
setDataSource(dataList);
}
}
)
axios.post() 方法 设置请求头
axios.post('/your-url', data, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${sessionStorage.getItem("token")}`
// other headers here...
}
});
设置了 Content-Type 头,指定了请求的数据格式为 JSON
标签:Axios,请求,headers,axios,设置,data From: https://www.cnblogs.com/qinghuanjing/p/17020318.html