reactjs - 具有给定令牌的 Axios 拦截器,React
问题描述
在此请求之后:
axios
.post(url_auth, obj)
.then(response => {
const info = response.data
this.setState({info})
})
.catch(error => {
console.log(error);
});
我在信息中存储了一个带有 id 和令牌的 JSON。(后台发给我)
我现在想将令牌存储在我提出的每个请求的标头中。
我该怎么做?我猜用拦截器?一旦我在拦截器中配置了标头(我试图了解如何),如何在我的请求中调用它?
非常感谢!
解决方案
推荐阅读
- c++ - 如何在 C++ 中使用正则表达式
- sharepoint - Blueprism 代码产生 403 禁止错误
- java - Application Insights for Java:如何创建子工作单元
- node.js - 在mac上安装docker后nodejs无法正常工作
- postgresql - Postgres 多列索引是否用于 OR 查询?
- r - 使用函数调用对 R data.table 进行子集化:如何返回结果向量而不是仅返回一个结果?
- python-3.x - 如何删除用 ax.arrow() 创建的箭头?
- java - 从mapstruct收到错误“目标属性的几个可能的源属性”时如何避免显式映射?
- vue.js - 如何在挂载期间获取嵌套子组件中的 div - Vue.js
- python-3.x - 名称未定义,但较早时有效,现在无效;完全相同的代码