vite-plugin-mock-dev-server 1.4.3 → 1.4.6
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 +28 -46
- package/README.zh-CN.md +18 -27
- package/dist/index.cjs +162 -144
- package/dist/index.d.cts +1 -1
- package/dist/index.js +126 -108
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -8,22 +8,21 @@
|
|
|
8
8
|
|
|
9
9
|
<br>
|
|
10
10
|
<p align="center">
|
|
11
|
-
<a href="https://www.npmjs.com/package/vite-plugin-mock-dev-server"><img alt="npm" src="https://img.shields.io/npm/v/vite-plugin-mock-dev-server?style=flat-square"></a>
|
|
12
|
-
<img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
|
|
13
|
-
<img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/vite-plugin-mock-dev-server/peer/vite?style=flat-square">
|
|
14
|
-
<img alt="npm" src="https://img.shields.io/npm/dt/vite-plugin-mock-dev-server?style=flat-square">
|
|
15
|
-
<br>
|
|
16
|
-
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/pengzhanbo/vite-plugin-mock-dev-server/lint.yml?style=flat-square">
|
|
17
|
-
<a href="https://app.fossa.com/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server?ref=badge_shield"><img alt="fossa status" src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server.svg?type=shield"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/vite-plugin-mock-dev-server"><img alt="npm" src="https://img.shields.io/npm/v/vite-plugin-mock-dev-server?style=flat-square"></a>
|
|
12
|
+
<img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
|
|
13
|
+
<img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/vite-plugin-mock-dev-server/peer/vite?style=flat-square">
|
|
14
|
+
<img alt="npm" src="https://img.shields.io/npm/dt/vite-plugin-mock-dev-server?style=flat-square">
|
|
15
|
+
<br>
|
|
16
|
+
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/pengzhanbo/vite-plugin-mock-dev-server/lint.yml?style=flat-square">
|
|
17
|
+
<a href="https://app.fossa.com/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server?ref=badge_shield"><img alt="fossa status" src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server.svg?type=shield"></a>
|
|
18
18
|
</p>
|
|
19
19
|
<br>
|
|
20
20
|
<p align="center">
|
|
21
|
-
<span>English</span> | <a href="/README.zh-CN.md">简体中文</a>
|
|
21
|
+
<span>English</span> | <a href="/README.zh-CN.md">简体中文</a>
|
|
22
22
|
</p>
|
|
23
23
|
<br>
|
|
24
24
|
<br>
|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
## Feature
|
|
28
27
|
|
|
29
28
|
- ⚡️ Lightweight, Flexible, Fast.
|
|
@@ -46,7 +45,6 @@
|
|
|
46
45
|
- ⚜️ Support `WebSocket Mock`
|
|
47
46
|
- 🗂 Support building small independent deployable mock services.
|
|
48
47
|
|
|
49
|
-
|
|
50
48
|
## Documentation
|
|
51
49
|
|
|
52
50
|
See the [documentation](https://vite-plugin-mock-dev-server.netlify.app/en/) to learn more.
|
|
@@ -60,7 +58,7 @@ See the [documentation](https://vite-plugin-mock-dev-server.netlify.app/en/) to
|
|
|
60
58
|
``` sh
|
|
61
59
|
# npm
|
|
62
60
|
npm i -D vite-plugin-mock-dev-server
|
|
63
|
-
# yarn
|
|
61
|
+
# yarn
|
|
64
62
|
yarn add vite-plugin-mock-dev-server
|
|
65
63
|
# pnpm
|
|
66
64
|
pnpm add -D vite-plugin-mock-dev-server
|
|
@@ -114,7 +112,6 @@ export default defineMock({
|
|
|
114
112
|
|
|
115
113
|
Vite plugin
|
|
116
114
|
|
|
117
|
-
|
|
118
115
|
`vite.config.ts`
|
|
119
116
|
``` ts
|
|
120
117
|
import { defineConfig } from 'vite'
|
|
@@ -127,13 +124,12 @@ export default defineConfig({
|
|
|
127
124
|
})
|
|
128
125
|
```
|
|
129
126
|
|
|
130
|
-
|
|
131
127
|
#### options
|
|
132
128
|
|
|
133
129
|
- `options.prefix`
|
|
134
130
|
|
|
135
131
|
**Type:** `string | string[]`
|
|
136
|
-
|
|
132
|
+
|
|
137
133
|
Configure custom matching rules for the mock server. Any request path starting with the value of `prefix` will be proxied to the corresponding target. If the `prefix` value starts with ^, it will be recognized as a RegExp.
|
|
138
134
|
|
|
139
135
|
> In general, `server.proxy` is sufficient to meet the needs. Adding this item is for compatibility with certain scenarios.
|
|
@@ -141,7 +137,7 @@ export default defineConfig({
|
|
|
141
137
|
**Default:** `[]`
|
|
142
138
|
|
|
143
139
|
- `options.wsPrefix`
|
|
144
|
-
|
|
140
|
+
|
|
145
141
|
**Type:** `string | string[]`
|
|
146
142
|
|
|
147
143
|
Configure the matching rules for the WebSocket service. Any request path starting with the value of `wsPrefix` and using the `ws/wss` protocol will be proxied to the corresponding target.
|
|
@@ -151,11 +147,10 @@ export default defineConfig({
|
|
|
151
147
|
> Different from using `viteConfig.server.proxy` by default for http mock, `websocket mock` does not use the ws-related configuration in `viteConfig.server.proxy`. Also, rules configured in `wsPrefix` cannot be configured simultaneously in `viteConfig.server.proxy`, as it will cause conflicts when starting the vite server because multiple instances of WebSocketServer cannot be implemented for the same request.
|
|
152
148
|
> This conflict is neither a problem with Vite nor with the plugin; it belongs to a reasonable error type. When switching between WebSocket Mock and WebSocket Proxy, please pay attention to avoid duplicate configurations that may cause conflicts.
|
|
153
149
|
|
|
154
|
-
|
|
155
|
-
- `option.include`
|
|
150
|
+
- `option.include`
|
|
156
151
|
|
|
157
152
|
**Type:** `string | string[]`
|
|
158
|
-
|
|
153
|
+
|
|
159
154
|
Configure to read mock files, which can be a directory, glob, or an array.
|
|
160
155
|
|
|
161
156
|
**Default:** `['mock/**/*.mock.{js,ts,cjs,mjs,json,json5}']` (Relative to the root directory.)
|
|
@@ -163,36 +158,35 @@ export default defineConfig({
|
|
|
163
158
|
- `options.exclude`
|
|
164
159
|
|
|
165
160
|
**Type:** `string | string[]`
|
|
166
|
-
|
|
161
|
+
|
|
167
162
|
When reading mock files for configuration, the files that need to be excluded can be a directory, glob, or array.
|
|
168
163
|
|
|
169
164
|
**Default:** `['**/node_modules/**','**/.vscode/**','**/.git/**']`
|
|
170
165
|
|
|
171
166
|
- `options.reload`
|
|
172
|
-
|
|
167
|
+
|
|
173
168
|
**Type:** `boolean`
|
|
174
169
|
|
|
175
170
|
When the mock resource is hot updated, only the data content is updated, but the page is not refreshed by default. If you want to refresh the page every time you modify the mock file, you can open this option.
|
|
176
171
|
|
|
177
172
|
- `options.cors`
|
|
178
|
-
|
|
173
|
+
|
|
179
174
|
**Type:** `boolean | CorsOptions`
|
|
180
175
|
|
|
181
176
|
Enable by default.
|
|
182
177
|
|
|
183
178
|
Configure to `cors`, see [cors](https://github.com/expressjs/cors#configuration-options)
|
|
184
179
|
|
|
185
|
-
|
|
186
180
|
**Default:** `true`
|
|
187
181
|
|
|
188
182
|
- `options.log`
|
|
189
|
-
|
|
183
|
+
|
|
190
184
|
**Type:** `boolean | 'info' | 'warn' | 'error' | 'silent'`
|
|
191
185
|
|
|
192
186
|
Enable log and configure log level.
|
|
193
187
|
|
|
194
188
|
- `options.formidableOptions`
|
|
195
|
-
|
|
189
|
+
|
|
196
190
|
Configure to `formidable`, see [formidable options](https://github.com/node-formidable/formidable#options)
|
|
197
191
|
|
|
198
192
|
**Default:** `{}`
|
|
@@ -207,7 +201,7 @@ export default defineConfig({
|
|
|
207
201
|
```
|
|
208
202
|
|
|
209
203
|
- `options.cookiesOptions`
|
|
210
|
-
|
|
204
|
+
|
|
211
205
|
Configure to `cookies`, see [cookies](https://github.com/pillarjs/cookies#new-cookiesrequest-response--options)
|
|
212
206
|
|
|
213
207
|
**Default:** `{}`
|
|
@@ -216,7 +210,7 @@ export default defineConfig({
|
|
|
216
210
|
|
|
217
211
|
The configuration needed to build a small, independently deployable mock service.
|
|
218
212
|
|
|
219
|
-
**Type:** `boolean | ServerBuildOptions`
|
|
213
|
+
**Type:** `boolean | ServerBuildOptions`
|
|
220
214
|
|
|
221
215
|
**Default:** `false`
|
|
222
216
|
|
|
@@ -241,7 +235,7 @@ export default defineConfig({
|
|
|
241
235
|
```
|
|
242
236
|
|
|
243
237
|
- `options.priority`
|
|
244
|
-
|
|
238
|
+
|
|
245
239
|
Custom path matching rule priority。[read more](#Custom-Path-Matching-Priority)
|
|
246
240
|
|
|
247
241
|
**Default:** `undefined`
|
|
@@ -473,11 +467,10 @@ type Response = http.ServerResponse<http.IncomingMessage> & {
|
|
|
473
467
|
}
|
|
474
468
|
```
|
|
475
469
|
|
|
476
|
-
|
|
477
470
|
> **Tips:**
|
|
478
|
-
>
|
|
479
|
-
> If you write mock files using json/json5,
|
|
480
|
-
> the 'response' method is not supported,
|
|
471
|
+
>
|
|
472
|
+
> If you write mock files using json/json5,
|
|
473
|
+
> the 'response' method is not supported,
|
|
481
474
|
> as is the function form that uses other fields.
|
|
482
475
|
|
|
483
476
|
## Share Mock Data
|
|
@@ -525,8 +518,8 @@ export default defineMock([
|
|
|
525
518
|
```
|
|
526
519
|
|
|
527
520
|
> **Tips:**
|
|
528
|
-
>
|
|
529
|
-
> The `defineMockData` function relies solely on the shared data support provided by `memory`.
|
|
521
|
+
>
|
|
522
|
+
> The `defineMockData` function relies solely on the shared data support provided by `memory`.
|
|
530
523
|
> If persistent mock data is required, it is recommended to use a `nosql` database like `lowdb` or `level`.
|
|
531
524
|
|
|
532
525
|
## Custom-Path-Matching-Priority
|
|
@@ -576,7 +569,6 @@ export default defineConfig({
|
|
|
576
569
|
> you can use static rules instead of `priority`,
|
|
577
570
|
> as static rules always have the highest priority.
|
|
578
571
|
|
|
579
|
-
|
|
580
572
|
## Example
|
|
581
573
|
|
|
582
574
|
`mock/**/*.mock.{ts,js,mjs,cjs,json,json5}`
|
|
@@ -598,7 +590,6 @@ export default defineMock({
|
|
|
598
590
|
})
|
|
599
591
|
```
|
|
600
592
|
|
|
601
|
-
|
|
602
593
|
**exp:** Only Support `GET` Method
|
|
603
594
|
``` ts
|
|
604
595
|
export default defineMock({
|
|
@@ -627,7 +618,6 @@ export default defineMock({
|
|
|
627
618
|
})
|
|
628
619
|
```
|
|
629
620
|
|
|
630
|
-
|
|
631
621
|
**exp:** Define multiple mock requests for the same URL and match valid rules with validators
|
|
632
622
|
``` ts
|
|
633
623
|
export default defineMock([
|
|
@@ -662,7 +652,6 @@ export default defineMock([
|
|
|
662
652
|
])
|
|
663
653
|
```
|
|
664
654
|
|
|
665
|
-
|
|
666
655
|
**exp:** Response Delay
|
|
667
656
|
``` ts
|
|
668
657
|
export default defineMock({
|
|
@@ -671,7 +660,6 @@ export default defineMock({
|
|
|
671
660
|
})
|
|
672
661
|
```
|
|
673
662
|
|
|
674
|
-
|
|
675
663
|
**exp:** The interface request failed
|
|
676
664
|
``` ts
|
|
677
665
|
export default defineMock({
|
|
@@ -681,7 +669,6 @@ export default defineMock({
|
|
|
681
669
|
})
|
|
682
670
|
```
|
|
683
671
|
|
|
684
|
-
|
|
685
672
|
**exp:** Dynamic route matching
|
|
686
673
|
``` ts
|
|
687
674
|
export default defineMock({
|
|
@@ -749,7 +736,6 @@ export default defineMock({
|
|
|
749
736
|
```
|
|
750
737
|
You need install `mockjs`
|
|
751
738
|
|
|
752
|
-
|
|
753
739
|
**exp:** Use `response` to customize the response
|
|
754
740
|
``` ts
|
|
755
741
|
export default defineMock({
|
|
@@ -769,7 +755,6 @@ export default defineMock({
|
|
|
769
755
|
})
|
|
770
756
|
```
|
|
771
757
|
|
|
772
|
-
|
|
773
758
|
**exp:** Use json / json5
|
|
774
759
|
``` json
|
|
775
760
|
{
|
|
@@ -780,8 +765,6 @@ export default defineMock({
|
|
|
780
765
|
}
|
|
781
766
|
```
|
|
782
767
|
|
|
783
|
-
|
|
784
|
-
|
|
785
768
|
**exp:** multipart, upload files.
|
|
786
769
|
|
|
787
770
|
use [`formidable`](https://www.npmjs.com/package/formidable#readme) to support.
|
|
@@ -789,7 +772,7 @@ use [`formidable`](https://www.npmjs.com/package/formidable#readme) to support.
|
|
|
789
772
|
<form action="/api/upload" method="post" enctype="multipart/form-data">
|
|
790
773
|
<p>
|
|
791
774
|
<span>file: </span>
|
|
792
|
-
<input type="file" name="files" multiple>
|
|
775
|
+
<input type="file" name="files" multiple="multiple">
|
|
793
776
|
</p>
|
|
794
777
|
<p>
|
|
795
778
|
<span>name:</span>
|
|
@@ -801,7 +784,7 @@ use [`formidable`](https://www.npmjs.com/package/formidable#readme) to support.
|
|
|
801
784
|
</form>
|
|
802
785
|
```
|
|
803
786
|
|
|
804
|
-
fields `files` mapping to `formidable.File`
|
|
787
|
+
fields `files` mapping to `formidable.File`
|
|
805
788
|
``` ts
|
|
806
789
|
export default defineMock({
|
|
807
790
|
url: '/api/upload',
|
|
@@ -948,5 +931,4 @@ You can access related `mock` interfaces through `localhost:8080/`.
|
|
|
948
931
|
|
|
949
932
|
[MIT](/LICENSE)
|
|
950
933
|
|
|
951
|
-
|
|
952
934
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server?ref=badge_large)
|
package/README.zh-CN.md
CHANGED
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
- ⚜️ 支持模拟 `WebSocket`
|
|
48
48
|
- 🗂 支持构建可独立部署的小型mock服务
|
|
49
49
|
|
|
50
|
-
|
|
51
50
|
## 文档
|
|
52
51
|
|
|
53
52
|
查看 [Documentation](https://vite-plugin-mock-dev-server.netlify.app/) 了解更多。
|
|
@@ -61,7 +60,7 @@
|
|
|
61
60
|
```sh
|
|
62
61
|
# npm
|
|
63
62
|
npm i -D vite-plugin-mock-dev-server
|
|
64
|
-
# yarn
|
|
63
|
+
# yarn
|
|
65
64
|
yarn add vite-plugin-mock-dev-server
|
|
66
65
|
# pnpm
|
|
67
66
|
pnpm add -D vite-plugin-mock-dev-server
|
|
@@ -92,7 +91,7 @@ export default defineConfig({
|
|
|
92
91
|
插件也会读取 `define` 配置, 支持在 mock 文件中直接使用。
|
|
93
92
|
|
|
94
93
|
> 因为一般场景下,我们只需要对有代理的url进行mock,这样才能通过 vite 提供的 http 服务进行 代理和 mock,
|
|
95
|
-
> 但你也可以使用 `options.prefix`配置 mock
|
|
94
|
+
> 但你也可以使用 `options.prefix`配置 mock
|
|
96
95
|
|
|
97
96
|
### 编写mock文件
|
|
98
97
|
|
|
@@ -114,7 +113,6 @@ export default defineMock({
|
|
|
114
113
|
|
|
115
114
|
vite plugin
|
|
116
115
|
|
|
117
|
-
|
|
118
116
|
`vite.config.ts`
|
|
119
117
|
```ts
|
|
120
118
|
import { defineConfig } from 'vite'
|
|
@@ -132,7 +130,7 @@ export default defineConfig({
|
|
|
132
130
|
- `options.prefix`
|
|
133
131
|
|
|
134
132
|
**类型:** `string | string[]`
|
|
135
|
-
|
|
133
|
+
|
|
136
134
|
为mock服务器配置自定义匹配规则。任何请求路径以 `prefix` 值开头的请求将被代理到对应的目标。如果 `prefix` 值以 `^` 开头,将被识别为 RegExp。
|
|
137
135
|
|
|
138
136
|
> 一般情况下, `server.proxy` 已经足够满足需求,添加此项是为了与某些场景兼容。
|
|
@@ -140,19 +138,19 @@ export default defineConfig({
|
|
|
140
138
|
**默认值:** `[]`
|
|
141
139
|
|
|
142
140
|
- `options.wsPrefix`
|
|
143
|
-
|
|
141
|
+
|
|
144
142
|
**类型:** `string | string[]`
|
|
145
143
|
|
|
146
144
|
配置 webSocket 服务 匹配规则。任何请求路径以 `wsPrefix` 值开头的 `ws/wss` 协议请求,将被代理到对应的目标。
|
|
147
145
|
如果`wsPrefix`值以 `^` 开头,将被识别为 RegExp。
|
|
148
146
|
|
|
149
147
|
> 与 http mock 默认使用 `viteConfig.server.proxy` 不同的是,`websocket mock` 不会使用 `viteConfig.server.proxy` 中的 ws 相关的配置,且配置在 `wsPrefix` 中的规则,不能同时配置在 `viteConfig.server.proxy`中,因为会导致在 vite 在启动服务时产生冲突,因为不能对同一个请求实现多个的 `WebSocketServer`实例。
|
|
150
|
-
> 该冲突既不是 `vite` 的问题,也不是插件的问题,这属于合理的错误类型。在进行 `WebSocket Mock`和 `WebSocket Proxy` 切换时,请注意配置不要出现重复导致冲突。
|
|
148
|
+
> 该冲突既不是 `vite` 的问题,也不是插件的问题,这属于合理的错误类型。在进行 `WebSocket Mock`和 `WebSocket Proxy` 切换时,请注意配置不要出现重复导致冲突。
|
|
151
149
|
|
|
152
|
-
- `option.include`
|
|
150
|
+
- `option.include`
|
|
153
151
|
|
|
154
152
|
**类型:** `string | string[]`
|
|
155
|
-
|
|
153
|
+
|
|
156
154
|
配置读取 mock文件,可以是一个 目录,glob,或者一个数组
|
|
157
155
|
|
|
158
156
|
**默认值:** `['mock/**/*.mock.{js,ts,cjs,mjs,json,json5}']` (相对于根目录)
|
|
@@ -160,7 +158,7 @@ export default defineConfig({
|
|
|
160
158
|
- `options.exclude`
|
|
161
159
|
|
|
162
160
|
**类型:** `string | string[]`
|
|
163
|
-
|
|
161
|
+
|
|
164
162
|
配置读取 mock文件时,需要排除的文件, 可以是一个 目录、glob、或者一个数组
|
|
165
163
|
|
|
166
164
|
**默认值:** `['**/node_modules/**', '**/.vscode/**', '**/.git/**']`
|
|
@@ -174,7 +172,7 @@ export default defineConfig({
|
|
|
174
172
|
**Default:** `false`
|
|
175
173
|
|
|
176
174
|
- `options.cors`
|
|
177
|
-
|
|
175
|
+
|
|
178
176
|
**Type:** `boolean | CorsOptions`
|
|
179
177
|
|
|
180
178
|
默认启用.
|
|
@@ -182,13 +180,13 @@ export default defineConfig({
|
|
|
182
180
|
配置 `cors`, 查看 [cors](https://github.com/expressjs/cors#configuration-options)
|
|
183
181
|
|
|
184
182
|
- `options.log`
|
|
185
|
-
|
|
183
|
+
|
|
186
184
|
**Type:** `boolean | 'info' | 'warn' | 'error' | 'silent'`
|
|
187
185
|
|
|
188
186
|
启动日志,以及配置日志打印级别
|
|
189
187
|
|
|
190
188
|
- `options.formidableOptions`
|
|
191
|
-
|
|
189
|
+
|
|
192
190
|
配置 `formidable`,查看 [formidable options](https://github.com/node-formidable/formidable#options)
|
|
193
191
|
|
|
194
192
|
**默认值:** `{}`
|
|
@@ -202,16 +200,16 @@ export default defineConfig({
|
|
|
202
200
|
})
|
|
203
201
|
```
|
|
204
202
|
- `options.cookiesOptions`
|
|
205
|
-
|
|
203
|
+
|
|
206
204
|
配置 `cookies`, 查看 [cookies](https://github.com/pillarjs/cookies#new-cookiesrequest-response--options)
|
|
207
205
|
|
|
208
206
|
**默认值:** `{}`
|
|
209
207
|
|
|
210
208
|
- `options.build`
|
|
211
|
-
|
|
209
|
+
|
|
212
210
|
需要构建可独立部署的小型mock服务时配置。
|
|
213
211
|
|
|
214
|
-
**类型:** `boolean | ServerBuildOptions`
|
|
212
|
+
**类型:** `boolean | ServerBuildOptions`
|
|
215
213
|
|
|
216
214
|
**默认值:**`false`
|
|
217
215
|
|
|
@@ -237,7 +235,7 @@ export default defineConfig({
|
|
|
237
235
|
```
|
|
238
236
|
|
|
239
237
|
- `options.priority`
|
|
240
|
-
|
|
238
|
+
|
|
241
239
|
自定义 路径匹配规则优先级。[查看更多](#自定义匹配优先级)
|
|
242
240
|
|
|
243
241
|
**默认值:** `undefined`
|
|
@@ -464,9 +462,8 @@ type Response = http.ServerResponse<http.IncomingMessage> & {
|
|
|
464
462
|
}
|
|
465
463
|
```
|
|
466
464
|
|
|
467
|
-
|
|
468
465
|
> **注意:**
|
|
469
|
-
>
|
|
466
|
+
>
|
|
470
467
|
> 如果使用 json/json5 编写 mock文件,则不支持使用 `response` 方法,以及不支持使用其他字段的函数形式。
|
|
471
468
|
|
|
472
469
|
## 共享 Mock 数据
|
|
@@ -516,11 +513,10 @@ export default defineMock([
|
|
|
516
513
|
```
|
|
517
514
|
|
|
518
515
|
> **注意:**
|
|
519
|
-
>
|
|
516
|
+
>
|
|
520
517
|
> `defineMockData` 仅是基于 `memory` 提供的共享数据支持,
|
|
521
518
|
> 如果需要做 mock 数据持久化,建议使用 `nosql`, 如 `lowdb` 或 `level` 等。
|
|
522
519
|
|
|
523
|
-
|
|
524
520
|
## 自定义匹配优先级
|
|
525
521
|
|
|
526
522
|
> 自定义规则仅影响包含动态参数的链接,如: `/api/user/:id`
|
|
@@ -599,7 +595,6 @@ export default defineMock({
|
|
|
599
595
|
})
|
|
600
596
|
```
|
|
601
597
|
|
|
602
|
-
|
|
603
598
|
**exp:** 在返回的响应头中,添加自定义 header 和 cookie
|
|
604
599
|
```ts
|
|
605
600
|
export default defineMock({
|
|
@@ -653,7 +648,6 @@ export default defineMock([
|
|
|
653
648
|
])
|
|
654
649
|
```
|
|
655
650
|
|
|
656
|
-
|
|
657
651
|
**exp:** 延迟接口响应:
|
|
658
652
|
```ts
|
|
659
653
|
export default defineMock({
|
|
@@ -737,7 +731,6 @@ export default defineMock({
|
|
|
737
731
|
```
|
|
738
732
|
请先安装 `mockjs`
|
|
739
733
|
|
|
740
|
-
|
|
741
734
|
**exp:** 使用 `response` 自定义响应
|
|
742
735
|
```ts
|
|
743
736
|
export default defineMock({
|
|
@@ -757,7 +750,6 @@ export default defineMock({
|
|
|
757
750
|
})
|
|
758
751
|
```
|
|
759
752
|
|
|
760
|
-
|
|
761
753
|
**exp:** 使用 json / json5
|
|
762
754
|
```json
|
|
763
755
|
{
|
|
@@ -768,7 +760,6 @@ export default defineMock({
|
|
|
768
760
|
}
|
|
769
761
|
```
|
|
770
762
|
|
|
771
|
-
|
|
772
763
|
**exp:** multipart, 文件上传.
|
|
773
764
|
|
|
774
765
|
通过 [`formidable`](https://www.npmjs.com/package/formidable#readme) 支持。
|
|
@@ -776,7 +767,7 @@ export default defineMock({
|
|
|
776
767
|
<form action="/api/upload" method="post" enctype="multipart/form-data">
|
|
777
768
|
<p>
|
|
778
769
|
<span>file: </span>
|
|
779
|
-
<input type="file" name="files" multiple>
|
|
770
|
+
<input type="file" name="files" multiple="multiple">
|
|
780
771
|
</p>
|
|
781
772
|
<p>
|
|
782
773
|
<span>name:</span>
|