etherreq 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/request.js +6 -6
package/package.json
CHANGED
package/src/request.js
CHANGED
|
@@ -18,14 +18,14 @@ instance.interceptors.request.use((config) => {
|
|
|
18
18
|
Authorization: token ? `Bearer ${token}` : undefined,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
// GET
|
|
21
|
+
// GET 请求启用缓存
|
|
22
22
|
if (config.method === 'GET' && !config.disableCache) {
|
|
23
23
|
const cacheKey = getCacheKey(config.url, config);
|
|
24
24
|
const cached = requestCache.get(cacheKey);
|
|
25
25
|
|
|
26
26
|
if (cached) {
|
|
27
|
-
//
|
|
28
|
-
return Promise.resolve(cached);
|
|
27
|
+
// ✅ 返回纯 data,不触发后续 fetch
|
|
28
|
+
return Promise.resolve(cached);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -40,11 +40,11 @@ instance.interceptors.response.use(
|
|
|
40
40
|
(response) => {
|
|
41
41
|
const config = response.config;
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
// 如果是 GET 请求且未禁用缓存,则写入缓存
|
|
44
44
|
if (config && config.method === 'GET' && !config.disableCache) {
|
|
45
45
|
const cacheKey = getCacheKey(config.url, config);
|
|
46
|
-
// 只缓存 data
|
|
47
|
-
requestCache.set(cacheKey, response.data);
|
|
46
|
+
// ✅ 只缓存 data 字段,确保是可序列化数据
|
|
47
|
+
requestCache.set(cacheKey, response.data);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
return response.data;
|