etherreq 1.0.14 → 1.0.15
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/etherreq.js +0 -6
- package/src/request.js +2 -1
package/package.json
CHANGED
package/src/etherreq.js
CHANGED
|
@@ -19,7 +19,6 @@ export const create = (defaultConfig = {}) => {
|
|
|
19
19
|
let response;
|
|
20
20
|
try {
|
|
21
21
|
const { url, method = 'GET', headers = {}, body } = config;
|
|
22
|
-
|
|
23
22
|
const options = {
|
|
24
23
|
method,
|
|
25
24
|
headers,
|
|
@@ -27,12 +26,7 @@ export const create = (defaultConfig = {}) => {
|
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
const res = await fetch(url, options);
|
|
30
|
-
|
|
31
29
|
const data = await res.json();
|
|
32
|
-
console.log(data);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
30
|
if (!res.ok) {
|
|
37
31
|
const error = new Error(`HTTP 错误: ${res.status} - ${res.statusText}`);
|
|
38
32
|
error.response = {
|
package/src/request.js
CHANGED
|
@@ -8,7 +8,6 @@ const instance = create({
|
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
// 请求拦截器:自动注入 token、Content-Type 和缓存处理
|
|
11
|
-
// src/request.js - 请求拦截器部分
|
|
12
11
|
instance.interceptors.request.use((config) => {
|
|
13
12
|
const token = localStorage.getItem('token');
|
|
14
13
|
|
|
@@ -22,6 +21,8 @@ instance.interceptors.request.use((config) => {
|
|
|
22
21
|
if (config.method === 'GET' && !config.disableCache) {
|
|
23
22
|
const cacheKey = getCacheKey(config.url, config);
|
|
24
23
|
const cached = requestCache.get(cacheKey);
|
|
24
|
+
console.log('缓存命中:', cacheKey);
|
|
25
|
+
console.log("缓存数据:",cached);
|
|
25
26
|
|
|
26
27
|
if (cached) {
|
|
27
28
|
// ✅ 返回缓存的 data 数据,中断后续请求流程
|