【发布时间】:2021-02-09 18:19:51
【问题描述】:
我尝试在 fetch 属性中根据 apollo 客户端上的response.status 更新缓存控制标头,我有一个自定义的 fetch 方法,但是当我使用 headers.set() 时出现错误
TypeError: 无法在 'Headers' 上执行 'set': Headers 是不可变的
const customFetch = (uri, options) => {
options.headers['Cache-Control'] = 'no-cache';
return fetch(uri, options).then(response => {
console.log(response.headers.get('cache-control'));
try {
if(response.status !== 301)
response.headers.set('Cache-Control', getNewCacheValue());
} catch (e) {
console.log(e);
}
return new BatchHttpLink({
fetch: customFetch,
uri: uri
});
【问题讨论】:
-
您的 customFetch 函数有两个返回语句,是不是拼写错误??你能更新问题吗?
标签: javascript fetch apollo apollo-client