Mock Configuration
Mock configuration is used to define the mock response behavior of a single interface.
Basic Structure
ts
import { defineMock } from 'vite-plugin-mock-dev-server'
export default defineMock({
url: '/api/test',
method: 'GET',
body: { message: 'Hello World' }
})Configuration Overview
| Configuration | Type | Required | Default | Description |
|---|---|---|---|---|
| url | string | Yes | - | Request path, supports dynamic parameters |
| method | Method | Method[] | No | ['GET','POST'] | Allowed HTTP methods |
| enabled | boolean | No | true | Whether to enable |
| status | number | No | 200 | Response status code |
| statusText | string | No | 'OK' | Response status text |
| headers | Headers | Function | No | - | Response headers |
| body | ResponseBody | Function | No | {} | Response body |
| response | Function | No | - | Custom response handling |
| delay | number | [number, number] | No | 0 | Response delay |
| cookies | ResponseCookies | Function | No | - | Response Cookies |
| validator | Validator | Function | No | - | Request validator |
| error | MockErrorConfig | No | - | Error simulation configuration |
Multiple Configurations
Multiple mock configurations can be exported in a single file:
ts
import { defineMock } from 'vite-plugin-mock-dev-server'
export default defineMock([
{
url: '/api/users',
method: 'GET',
body: []
},
{
url: '/api/users',
method: 'POST',
body: { id: 1 }
}
])Detailed Documentation
View API Reference - MockHttpItem for complete configuration item descriptions and examples.
