nuxt-custom-fetch 1.0.8 → 1.1.0
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/README.md +62 -38
- package/dist/module.json +1 -1
- package/dist/runtime/ajax.d.ts +1 -1
- package/dist/runtime/ajax.mjs +5 -3
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
实例化全局 CustomFetch
|
|
8
8
|
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
```ts
|
|
10
|
+
{
|
|
11
|
+
baseURL?: string
|
|
12
|
+
paramsHandler?: (params: FetchOptions['params']) => FetchOptions & HTTPConfig
|
|
13
|
+
extraParams?: string[]
|
|
14
|
+
offline?: () => void
|
|
15
|
+
}
|
|
14
16
|
```
|
|
15
17
|
|
|
16
18
|
### baseURL
|
|
@@ -28,8 +30,9 @@ offline?: () => void
|
|
|
28
30
|
|
|
29
31
|
### 请求-响应拦截
|
|
30
32
|
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
+
```ts
|
|
34
|
+
{
|
|
35
|
+
onRequest?: ({ request, options }: {
|
|
33
36
|
request: FetchRequest
|
|
34
37
|
options: FetchOptions
|
|
35
38
|
}) => void
|
|
@@ -60,6 +63,7 @@ onRequest?: ({ request, options }: {
|
|
|
60
63
|
options: FetchOptions
|
|
61
64
|
response: FetchResponse<any>
|
|
62
65
|
}) => void
|
|
66
|
+
}
|
|
63
67
|
```
|
|
64
68
|
|
|
65
69
|
## 实例方法
|
|
@@ -83,45 +87,65 @@ const key = hash(JSON.stringify(restConfig) + url)
|
|
|
83
87
|
|
|
84
88
|
### fetchOptions
|
|
85
89
|
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
```ts
|
|
91
|
+
interface fetchOptions {
|
|
92
|
+
baseURL?: string
|
|
93
|
+
key?: string
|
|
94
|
+
body?: RequestInit['body'] | Record<string, any>
|
|
95
|
+
useParamsHandler: HTTPConfig['paramsHandler']
|
|
96
|
+
paramsHandler: HTTPConfig['paramsHandler']
|
|
97
|
+
params?: SearchParameters
|
|
98
|
+
query?: SearchParameters
|
|
99
|
+
parseResponse?: (responseText: string) => any
|
|
100
|
+
responseType?: R
|
|
101
|
+
response?: boolean
|
|
102
|
+
retry?: number | false
|
|
103
|
+
onRequest?(context: FetchContext): Promise<void> | void
|
|
104
|
+
onRequestError?(
|
|
105
|
+
context: FetchContext & {
|
|
106
|
+
error: Error
|
|
107
|
+
}
|
|
108
|
+
): Promise<void> | void
|
|
109
|
+
onResponse?(
|
|
110
|
+
context: FetchContext & {
|
|
111
|
+
response: FetchResponse<R>
|
|
112
|
+
}
|
|
113
|
+
): Promise<void> | void
|
|
114
|
+
onResponseError?(
|
|
115
|
+
context: FetchContext & {
|
|
116
|
+
response: FetchResponse<R>
|
|
117
|
+
}
|
|
118
|
+
): Promise<void> | void
|
|
119
|
+
}
|
|
108
120
|
```
|
|
109
121
|
|
|
110
|
-
### AsyncDataOptions
|
|
122
|
+
### AsyncDataOptions
|
|
111
123
|
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
124
|
+
```ts
|
|
125
|
+
// AsyncDataOptions<DataT>
|
|
126
|
+
{
|
|
127
|
+
server?: boolean;
|
|
128
|
+
lazy?: boolean;
|
|
129
|
+
default?: () => DataT | Ref<DataT> | null;
|
|
130
|
+
transform?: Transform;
|
|
131
|
+
pick?: PickKeys;
|
|
132
|
+
watch?: MultiWatchSources;
|
|
133
|
+
immediate?: boolean;
|
|
134
|
+
}
|
|
120
135
|
```
|
|
121
136
|
|
|
122
137
|
## 使用方式
|
|
123
138
|
|
|
139
|
+
```bash
|
|
140
|
+
pnpm add nuxt-custom-fetch
|
|
141
|
+
```
|
|
142
|
+
|
|
124
143
|
```ts
|
|
144
|
+
// nuxt.config.ts
|
|
145
|
+
export default defineNuxtConfig({
|
|
146
|
+
modules: ['nuxt-custom-fetch']
|
|
147
|
+
})
|
|
148
|
+
|
|
125
149
|
// ajax.ts文件
|
|
126
150
|
import type { FetchOptions } from 'ofetch'
|
|
127
151
|
const ajax = new CustomFetch({
|
package/dist/module.json
CHANGED
package/dist/runtime/ajax.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { _AsyncData, AsyncDataOptions } from 'nuxt/dist/app/composables/asyncData';
|
|
2
2
|
import { HTTPConfig, Interceptors, AjaxConfig } from './type';
|
|
3
|
-
export declare const ajax: <DataT, ErrorT = Error | null>(url: string, key: string, config: AjaxConfig, options?: AsyncDataOptions<DataT,
|
|
3
|
+
export declare const ajax: <DataT, ErrorT = Error | null>(url: string, key: string, config: AjaxConfig, options?: AsyncDataOptions<DataT, DataT, import("nuxt/dist/app/composables/asyncData").KeysOf<DataT>, null> | undefined) => Promise<_AsyncData<DataT, ErrorT>>;
|
|
4
4
|
export declare class CustomFetch {
|
|
5
5
|
baseURL: any;
|
|
6
6
|
params: HTTPConfig;
|
package/dist/runtime/ajax.mjs
CHANGED
|
@@ -53,10 +53,12 @@ function getKey(url, config, extraParams = []) {
|
|
|
53
53
|
const Noop = () => {
|
|
54
54
|
};
|
|
55
55
|
export class CustomFetch {
|
|
56
|
+
baseURL;
|
|
57
|
+
params = {};
|
|
58
|
+
baseParamsHandler;
|
|
59
|
+
interceptors = {};
|
|
60
|
+
offline = Noop;
|
|
56
61
|
constructor(config = { baseURL: "" }) {
|
|
57
|
-
this.params = {};
|
|
58
|
-
this.interceptors = {};
|
|
59
|
-
this.offline = Noop;
|
|
60
62
|
this.params = {
|
|
61
63
|
...config
|
|
62
64
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-custom-fetch",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@nuxt/kit": "^3.
|
|
28
|
+
"@nuxt/kit": "^3.8.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@nuxt/module-builder": "^0.2.1",
|
|
32
|
-
"@nuxt/schema": "^3.
|
|
33
|
-
"@nuxtjs/eslint-config-typescript": "^12.
|
|
34
|
-
"eslint": "^8.
|
|
35
|
-
"nuxt": "^3.
|
|
32
|
+
"@nuxt/schema": "^3.8.1",
|
|
33
|
+
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
34
|
+
"eslint": "^8.53.0",
|
|
35
|
+
"nuxt": "^3.8.1"
|
|
36
36
|
}
|
|
37
37
|
}
|