mock模拟后台数据
import Mock from ‘mockjs‘ const Random = Mock.Random // 获取random对象,随机生成各种数据,具体请翻阅文档 const domain = ‘http://mockjs.com/api‘ // 定义默认域名,随便写 const code = 200 // 返回的状态码const postData = function(req) {
let listData=[] let totalSize = 30 let pagination = JSON.parse(req.body) let pageSize = pagination.pageSize; // 随机生成数据 for (let i = 0; i < pageSize; i++) { let post = { id: i, pfbmc: Random.name(), pshdmc: Random.csentence(10, 25), // 随机生成名字 pshdsj: Random.date() + ‘ ‘ + Random.time(), // 随机生成年月日 + 时间 zt: "启用" } listData.push(post) } return { // 返回状态码和文章数据posts code, result:1, info:{list:listData,totalSize: totalSize,} } } Random.extend({ name: function() { var name = [‘关于智能手机的评分表‘, ‘关于as的评分表‘, ‘关于saw的评分表‘, ‘关于wqwq的评分表‘, ‘关于gtrg的评分表‘, ‘任正非回应退休‘, ‘新发展理念‘, ‘20字好干部标准‘, ‘五位一体‘, ‘强富美高‘, ‘供给侧结构性改革‘, ‘三解三促‘,‘三会一课‘,‘四个进一步‘,‘三次大讨论‘,‘三个新成效‘,‘五查摆五强化‘,‘两聚一高‘,‘抓项目、转作风、促发展‘,‘三工程一计划‘] return this.pick(name) //pick:从list中随机选取一个元素 }, }) Mock.mock(`${domain}/gridTable/posts`, /get|post/i, postData); // 定义请求链接,类型,还有返回数据
//删除数据 const list = function (options) { let rtype = options.type.toLowerCase(); //获取请求类型 switch (rtype) { case ‘get‘: break; case ‘post‘: let id = parseInt(JSON.parse(options.body).id) //获取删除的id listData = listData.filter(function(val){ return val.id!=id;//把这个id对应的对象从数组里删除 }); break; default: } return { code, info:{list:listData} } //返回这个数组,也就是返回处理后的假数据 } Mock.mock(`${domain}/deletes`,/get|post/i, list);//删除数据
相关推荐
snowphy 2020-08-19
hwm 2020-06-14
free0day 2020-06-14
beibeijia 2020-06-07
84224552 2020-05-31
droidpioneer的IT 2020-05-20
85344193 2020-05-17
beibeijia 2020-05-16
Teamomc 2020-02-21
jxiao000 2020-02-20
MrHaoNan 2020-02-20
nimeijian 2020-02-15
Safari浏览器 2020-01-12
maicowxp 2019-12-29
TimeSky 2020-01-11
80487608 2014-07-04
aNian 2019-12-26
SDUTACM 2019-12-19