Mock.Random 是一个工具类,是一款模拟数据生成器。
Mock.Random 的方法在数据模板中称为『占位符』,书写格式为 @占位符(参数 [, 参数]) 。
var Random = Mock.Random Random.email()// => "n.clark@miller.io" Mock.mock('@email')// => "y.lee@lewis.org" Mock.mock( { email: '@email' } )
//引入mockjsimport Mock from 'mockjs' const Random = Mock.Random;//使用mockjs模拟数据 Mock.mock('/api/msdk/proxy/query_common_credit', (req, res) => { return { "ret":0, "data": { "mtime": Random.datetime(),//随机生成日期时间 "score": Random.natural(1, 800),//随机生成1-800的数字 "rank": Random.natural(1, 100),//随机生成1-100的数字 "stars": Random.natural(0, 5),//随机生成1-5的数字 "nickname": Random.cname()//随机生成中文名字 }}});
Type |
Method |
Basic |
boolean, natural, integer, float, character, string, range, date, time, datetime, now |
Image |
image, dataImage |
Color |
color |
Text |
paragraph, sentence, word, title, cparagraph, csentence, cword, ctitle |
Name |
first, last, name, cfirst, clast, cname |
Web |
url, domain, email, ip, tld |
Address |
area, region |
Helper |
capitalize, upper, lower, pick, shuffle |
Miscellaneous |
guid, id |