每次单独添加header
axios.post(`/api`, obj, {
headers: {'Token': 'xxxxx'}
})
添加默认header头
axios.defaults.headers.common['Token'] = "token";
别忘了后端要设置允许的自定义header参数
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD");
response.setHeader("Access-Control-Allow-Headers", "content-type,Token");
response.setHeader("Access-Control-Max-Age", "3600");
if (request.getMethod().equals("OPTIONS")){
response.setStatus(response.SC_OK);
}