Skip to content
On this page

使用 mockjs库

通过 mockjs 库生成 mock data。

TIP

你需要自行安装 mockjs

sh
pnpm add -D mockjs
pnpm add -D mockjs
ts
import Mock from 'mockjs'
import { defineMock } from 'vite-plugin-mock-dev-server'

export default defineMock({
  url: '/api/test',
  body: Mock.mock({
    'list|1-10': [{
      'id|+1': 1
    }]
  })
})
import Mock from 'mockjs'
import { defineMock } from 'vite-plugin-mock-dev-server'

export default defineMock({
  url: '/api/test',
  body: Mock.mock({
    'list|1-10': [{
      'id|+1': 1
    }]
  })
})

Released under the MIT License.