翻页 (get)(分页 复制接口api地址输入浏览器,输入两个参数,api?page=1&pageSize=10 )
{
"code": 0, //成功
"counts": 0,
"success": true,
"total": 1000, //总的数据长度
"list": function({
_req,
Mock
}) {
let i = 0,
_data = [],
page = _req.query.page, //当前页数
pageSize = _req.query.pageSize, //每次返回的条数
len = (1000 - pageSize * (page - 1)) < pageSize ? (1000 - pageSize * (page - 1)) : pageSize;
for (i; i < len; i++) {
_data.push(
Mock.mock({
"id": (page - 1) * pageSize + (i + 1),
"name|1": [
'钢铁战狼', '梦之队',
'博时基金', '平安保险'
],
"urlImg|1": [
'https://goss.veer.com/creative/vcg/veer/612/veer-134669323.jpg',
'https://goss2.veer.com/creative/vcg/veer/612/veer-133071017.jpg',
'https://goss.veer.com/creative/vcg/veer/612/veer-147395960.jpg',
'https://goss4.veer.com/creative/vcg/veer/612/veer-161959036.jpg'
],
"num": "123456789"
})
);
}
return _data;
},
"msg": "请求数据成功"
}
2.登陆 (username=admin&password=admin)
{
code: function({
_req
}) {
if (_req.body.username === 'admin' && _req.body.password === 'admin') {
return 20000
} else {
return 50000
}
},
data: function({
_req
}) {
if (_req.body.username === 'admin' && _req.body.password === 'admin') {
return {
token: "admin"
}
} else {
return "登录账号不对" + _req.body.username
}
}
}
3.购物车
{
"data": {
"code": 0,
"message": "success",
"list|10-20": [{
"id": "@id",
"title": "@ctitle",
"index|+1": 0,
"price|1-100.2": 0,
"img": "@image(200x100, #FF6600)",
"sprice": function() {
return this.price - 3;
},
"store|2-20": 1
}]
}
}
4.用户信息列表
{
"status": 0,
"err_msg": 'ok',
// name可以不写,这里只是方便查看
name: function({
_req
}) {
return _req.query.name
},
data: function({
_req,
Mock
}) {
var nameArr = ["张黎明", "张凯阳", "孙苗青", "木木", "刘诗诗", "杨幂", "张韶涵"]
var name = _req.query.name ? (nameArr.indexOf(_req.query.name) > 0 ? _req.query.name : null) : nameArr
var obj = name ? Mock.mock({
"list|3-10": [{
"name|1": name,
"url": "@url",
"email": "@email",
"address": "@county(true)",
"string|1-10": "",
"number|1-100": 100,
"boolean|1-2": true,
"object|2": {
"310000": "上海市",
"320000": "江苏省",
"330000": "浙江省"
}
}]
}) : {}
return obj
}
}
5.用户ip地址
{
"status": 0,
name: function({
_req
}) {
return _req.query.name
},
data: function({
_req,
Mock
}) {
return _req.query.name ? {
id: Mock.mock("@id()"),
cname: Mock.mock("@cname()"),
} : {}
},
"list|1-4": [{
"id": "@id",
"name": "@cname",
"IP": "@ip",
"email": "@email",
}]
}
token
{
code: function({
_req
}) {
if (_req.query.token === 'admin') {
return 20000
} else {
50000
}
},
data: function({
_req
}) {
if (_req.query.token === 'admin') {
return {
roles: [
"admin"
],
name: "admin",
avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif"
}
} else {
return "登录失败"
}
}
}
q
共同学习,写下你的评论
评论加载中...
作者其他优质文章