Mock.setup({
timeout: 400
})
Mock.setup({
timeout: ‘200-600’
})
目前,接口 Mock.setup( settings ) 仅用于配置 Ajax 请求,将来可能用于配置 Mock 的其他行为。
| 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 |
| 方法 | 说明 |
| :-- | :-- |
| Mock.Random.boolean() | 返回一个随机的布尔值 |
| Random.natural() | 返回一个随机的自然数(大于等于 0 的整数) |
| Random.integer() | 返回一个随机的整数 |
| Random.float() | 返回一个随机的浮点数 |
| Random.character() | 返回一个随机字符 |
| Random.string() | 返回一个随机字符串 |
| Random.range( start?, stop, step? ) | 返回一个整型数组 |
示例
//日期
Random.date() // “2012-10-23”
Random.date(‘yyyy-MM-dd’) // “2275-04-27”
Random.date(‘yy-MM-dd’) // “20-01-08”
//时间
Random.time() // “05:06:06”
//日期和时间
Random.datetime(‘yyyy-MM-dd HH:mm:ss’)
//当前的日期和时间
Ranndom.now()
// 生成随机域名
Random.domain() // “nurou.org.cn”
//生成随机URL
Random.url() // “news://wrmt.na/rbcgbws”
//生成随机IP
Random.ip() // “74.97.41.159”
//生成随机省份:
Random.province() //“海南省”
//生成随机城市:
Random.city() // “澳门半岛”
//生成在某个省份的某个城市:
Random.city(true) // “广东省 广州市”
//随机生成颜色,格式为 ‘#RRGGBB’
Random.color()
Random.hex()
//随机生成颜色,格式为’rgb(r, g, b)’
Random.rgb()
//随机生成颜色,格式为 ‘rgba(r, g, b, a)’
Random.rgba()
//随机生成颜色,格式为 ‘hsl(h, s, l)’
Random.hsl()
//生成一条随机的中文句子:
Random.csentence() // “会候句子解包党心要按总场火义字个片精。”
Random.csentence(5) // “文斗领拉米。”
Random.csentence(3, 5) // “住验住”
注意:
1、默认一条句子里的汉字个数在12和18之间
2、通过Random.csentence( length )指定句子的汉字个数