大佬教程收集整理的这篇文章主要介绍了mockjs数据占位符,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
mock.Random 是一个工具类,用于生成各种随机数据。 mock.Random 的方法在数据模板中称为『占位符』,书写格式为 @占位符(参数 [, 参数]) 。
内置方法列表:
Type | @H_645_9@method|
---|---|
Basic | Boolean, natural, Integer, float, character, String, range, date, time, datetiR_384_11845@e, 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 |
guid, id |
可以生成随机的基本数据类型:
let mock = require('mockjs')
let data = mock.mock({
'list|10': [{
'id|+1': 1,
'name':'@String',//字符串
'point':'@Integer',//整形
'birthday':'@date'//日期
}]
})
// 输出结果
console.log(JSON.Stringify(data,null,2))
let mock = require('mockjs')
let data = mock.mock({
'list|10': [{
'id|+1': 1,
'name':'@String',
'point':'@Integer',
'birthday':'@date',
'pic':'@image'//随机生成图片地址
}]
})
// 输出结果
console.log(JSON.Stringify(data,null,2))
let mock = require('mockjs')
let data = mock.mock({
'list|10': [{
'id|+1': 1,
'name':'@String',
'point':'@Integer',
'birthday':'@date',
'pic':'@image',
'title':'@title',//标题
'content':'@cword(100)'//文本内容
}]
})
// 输出结果
console.log(JSON.Stringify(data,null,2))
let mock = require('mockjs')
let data = mock.mock({
'list|10': [{
// 属性 id 是一个自增数,起始值为 1,每次增 1
'id|+1': 1,
'name':'@cname',
'ename':'@last',
'cfirst':'@cfirst',
'point':'@Integer',
'birthday':'@date',
'pic':'@image',
'title':'@title',
'content':'@cword(100)'
}]
})
// 输出结果
console.log(JSON.Stringify(data,null,2))
let mock = require('mockjs')
let data = mock.mock({
'list|10': [{
'id|+1': 1,
'name':'@cname',
'ename':'@last',
'cfirst':'@cfirst',
'point':'@Integer',
'birthday':'@date',
'pic':'@image',
'title':'@title',
'content':'@cword(100)',
'url':"@url",//url地址
'ip':"@ip",//ip地址
'email':"@email"//邮政
}]
})
// 输出结果
console.log(JSON.Stringify(data,null,2)
let mock = require('mockjs')
let data = mock.mock({
'list|10': [{
'id|+1': 1,
'name':'@cname',
'ename':'@last',
'cfirst':'@cfirst',
'point':'@Integer',
'birthday':'@date',
'pic':'@image',
'title':'@title',
'content':'@cword(100)',
'url':"@url",
'ip':"@ip",
'email':"@email",
'area':'@region',//区域
'address':'@county(true)'//省市区
}]
})
// 输出结果
console.log(JSON.Stringify(data,null,2))
以上是大佬教程为你收集整理的mockjs数据占位符全部内容,希望文章能够帮你解决mockjs数据占位符所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。