mockjs生成随机数据参数介绍

1203 ℃

1、先引入Random方法

const Random = Mock.Random

2、随机参数介绍

title: Random.ctitle(), //Random.ctitle(min,max) 随机产生一个中文标题,长度默认在3-7之间
content: Random.cparagraph(), //Random.cparagraph(min,max) 随机生成一个中文段落,段落里句子个数默认3-7个
time: Random.date(), //Random.date() 指定生成的日期字符串格式
img: Random.image(), // 生成默认图片image( size, background, foreground, format, text )
  //size:尺寸,格式为:‘宽x高’
​  //background:背景色,格式为:#FFFFFF
​  //text:图片上显示的文本
​  //foreground:广本颜色
​  //format:图片格式,可选值包括:png、gif、jpg。
  //如:image('200x100', '#ffcc33', '#FFF', 'png', '!')
username: Random.cname(), //生成默认名字
province: Random.province(),//随机省份
city: Random.city(),//随机城市,Random.city(true) 新增省份
county:Random.city(),//随机区县,Random.city(true) 新增省份、市
region: Random.region(), //随机区域,如:华北、西北
code: Random.zip(), //随机地区邮编
idCard: Random.ID(), //随机身份证
guid: Random.GUID(), //随机GUID // => "662C63B4-FD43-66F4-3328-C54E3FF0D56E"
base64: Random.Base64(), //Base64图片编码,dataImage(size,text)
color: Random.color(), //随机生成颜色,可以生成不同类型:hex、rgb、rgba、hsl
num: Random.integer(10, 10000), //生成整数,还可以生成不同类型:natural(自然数)和:
natural: Random.natural(), //自然数
float: Random.float(min,max,dmin,dmax), //小数,dmin:小数部分位数最小值,dmax:小数部分位数最大
range: range(min,max,step), //整数整组,step:递增的步长

除了上面这些之外,还有

1.单个字符
Random.character
Random.character(‘lower/upper/number/symbol’)
Random.character(pool)

2.字符串
Random.string
Random.string(length)
Random.string(min,max)

3.英文单词
Random.word
Random.word(length)
Random.word(min,max)

4.英文句子
Random.sentence
Random.sentence(len)
Random.sentence(min,max)

5.英文段落
Random.paragraph
Random.paragraph(len)
Random.paragraph(min,max)

6.中文汉字
Random.cword
Random.cword(pool)
Random.cword(len)
Random.cword(pool,len)
Random.cword(min,max)
Random.cword(pool,min,max)

Random.cword()
// => "干"
Random.cword('零一二三四五六七八九十')
// => "六"
Random.cword(3)
// => "别金提"
Random.cword('零一二三四五六七八九十', 3)
// => ""七七七""
Random.cword(5, 7)
// => "设过证全争听"
Random.cword('零一二三四五六七八九十', 5, 7)
// => "九七七零四"
7.中文句子
Random.csentence
Random.csentence(len)
Random.csentence(min,max)

8.中文段落
Random.cparagraph
Random.cparagraph(len)
Random.cparagraph(min,max)

9.中文标题
Random.ctitle
Random.ctitle(len)
Random.ctitle(min,max)

10.英文名
Random.first——名
Random.last——姓
Random.name——姓名
Random.name(middle)
​ middle:是否生成中间名字

11.中文名
Random.cfirst——姓
Random.clast——名
Random.cname——姓名

12.生成一个IP
Random.ip

13.生成一个Email
Random.email
Random.email(domain)
​ domain:指定域名

14.生成域名
Random.domain

15.生成URL
Random.url
Random.url(protocol,host)
​ protocol:指定协议,例如HTTP
​ host:指定域名

16.生成时间
Random.date
Random.time
Random.datetime

17.格式化时间
可以通过 format 参数设置时间的格式
Random.date(format)
Random.time(format)
Random.datetime(format)

vue项目生产环境中使用mock数据(mockjs和vite-plugin-mock)

wordpress当前分类下随机文章调用代码

js接口批量新增参数(?/&)后缀不一样

js获取链接?后面所有参数

mock.js用法实例

标签: mockjs, 参数, 生成时间, 随机读取

上面是“mockjs生成随机数据参数介绍”的全面内容,想了解更多关于 mockjs 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_2087.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

mysql哪些语句可以获取前10条数据
利用CSS3做一个星级评分样式
nodejs如何将数字转字符串
php语法中比较运算符“==”符号怎么用
php语法+mysql语法查询指定日期范围内的数据