如何使用redux saga在api调用的标头中添加令牌?
const response = yield call(post, url, data.payload);
第一个arg post
是您的api调用函数,redux-saga只是执行此函数并获得响应,因此您应将令牌添加到您的api调用函数中,而不是redux-saga。
您使用的是哪个api util?这两个是比较流行的api调用库。
fetch(
'url',
{
...
headers: {
'Authorization': 'Bearer '+ /* your token string */
}
}
);
import axios from 'axios';
export const api = axios.create({
baseURL: process.env.REACT_APP_IP,
timeout: 60000,
headers: {'Authorization': 'Bearer '+ /* your token string */}
});