常用mock写法
安装依赖
npm install mockjs
书写示例
var Mock = require("mockjs");
var Random = Mock.Random;
for (var i = 0; i < 10; i++) {
let obj = {
id: Random.id(), // 身份证号
guid: Random.guid(),
name: Random.cname(),
age: Random.integer(20, 50),
asset: Random.float(200, 500000, 1, 6),
married: Random.boolean(),
birth: Random.datetime("yyyy-MM-dd HH:mm:ss"), // 值是指定格式的日期字符串
// birth2: new Date(Random.datetime("yyyy-MM-dd HH:mm:ss")), // 值是 Date 类型
addr: `${Random.province()}-${Random.city()}-${Random.county()}`,
email: Random.email("qq.com"),
// word: Random.cword(2, 5),
// string: Random.string(),
title: Random.ctitle(10, 15),
// senetence: Random.csentence(15, 20),
// paragraph: Random.cparagraph(),
};
console.log(obj);
}
样例数据
{
id: '130000198405266751',
guid: '4eAD105F-77F2-BccD-dB1d-3C70bFC71fE8',
name: '萧娜',
age: 37,
asset: 336507.64,
married: true,
birth: '2008-12-23 18:39:11',
birth2: 1983-11-01T22:18:52.000Z,
addr: '贵州省-重庆市-巴南区',
email: 'u.mbht@qq.com',
word: '族现制万类',
string: 'AH6H',
title: '期对油状已边自划现新龙',
senetence: '二号究克共或党县团或革亲事离容却进压今。',
paragraph: '任派十专层件离想相样构支边八代取还展。反与但角量及亲矿元加节做改经动存。成总节江上对山型儿除土价比两。严书广由京江家养专员将即革土眼如快。律
林近信使后八好铁世相任是原题出。平例每热难区着世老个济造格斯。'
}
具体所有写法,官方参考: http://mockjs.com/examples.html