【发布时间】:2018-08-13 01:07:15
【问题描述】:
如何在使用带有 react 的 API 时传递动态 JWT x-access-token?我知道如何使用 fetch 方法使用 API。
componentDidMount(){
fetch('http://example.com/api/admin/dailyPosts')
.then(response => response.json())
.then(response => {
this.setState({
postCount: response
})
})
}
在安慰 this.state.postCount 时,我得到一个空数组,因为没有提供令牌。那么如何将动态令牌传递给这个 API?
【问题讨论】:
-
你的服务器端是什么样子的?您使用的是 express 或 passport.js 之类的吗?
-
这和 React 有什么关系?
-
不,我没有使用快递或护照。我只是在处理 create-react-app 模块。