Created
May 29, 2022 11:46
-
-
Save fishyer/049ed33d74821ac4664f8ed33cf82f56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | |
var Mock = require('mockjs') | |
var Random = Mock.Random | |
var data = Mock.mock({ | |
// 属性 list 的值是一个数组,其中含有 1 到 20 个元素 | |
'list|1-20': [{ | |
// 属性 id 是一个自增数,起始值为 1,每次增 1 | |
'id|+1': 1, | |
// 随机生成一个布尔值,值为 value 的概率是 min / (min + max),值为 !value 的概率是 max / (min + max)。 | |
'star|1-9': true, | |
// 生成一个浮点数,整数部分大于等于 min、小于等于 max,小数部分保留 dmin 到 dmax 位。 | |
'score|1-100.1-2': 1, | |
// 随机中文名 | |
'name': Random.cname(), | |
// 随机日期 | |
'birthday': Random.date('yyyy-MM-dd'), | |
// 随机地址-省市区 | |
'address': Random.county(true), | |
// 随机正则表达式 | |
'regex': /\d{4,6}/ | |
}], | |
}) | |
export default function handler(req, res) { | |
res.status(200).json({ | |
data: data | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment