Blogger Information
Blog 26
fans 0
comment 0
visits 12188
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
mockjs生成文章数据
高空中的云
Original
419 people have browsed it

安装

npm install mockjs 如果项目中没有安装mockjs,执行该命令进行安装

  1. const Mock = require('mockjs')
  2. const article = {
  3. 'id|+1': 1, // 文章id
  4. 'categoryid|1-5': 1, //栏目id
  5. title:'@ctitle(10,15)', //标题
  6. introduction: '@csentence(20,30)', //简介
  7. content: `@cparagraph(3,8)`, //内容详情
  8. img: `@image('200x200')`, // 图片url
  9. author: '@cname()', //作者
  10. 'time': `@datetime('yyyy年M月d日 H时m分s秒')`, // 发布日期
  11. }
  12. const opts = {
  13. 'articles|10': [article],
  14. }
  15. const data = Mock.mock(opts)
  16. console.log(JSON.stringify(data, null, 4))

生成数据如下

  1. {
  2. "articles": [
  3. {
  4. "id": 1,
  5. "categoryid": 3,
  6. "title": "变物连美直整生每点温代",
  7. "introduction": "越速层众同传因和时果积很地值现完正劳理十资关非元立老清习。",
  8. "content": "展油或专常层太在层为场断处严容。适断革部收少构放类世存见光快叫流品。区却太第例活省好只月话南难度除。备调于领林大石九比民海部种金这他但。积理建示表见酸走一果改候美解上。影把传影片何劳油圆业率体。还构而决东才什金育白目每该于平农。",
  9. "img": "http://dummyimage.com/200x200",
  10. "author": "阎丽",
  11. "dateTime": "2002年8月4日 0时36分34秒"
  12. },
  13. {
  14. "id": 2,
  15. "categoryid": 4,
  16. "title": "资世更什第天清以自以成",
  17. "introduction": "算下样使器是代约存团大万用片儿真华只传织确素四治提况清响还。",
  18. "content": "安或类离方表品业机车求团使众一。统设素九或属相容难火她生五育清历。题放格转至千元平干分通火存平被。任格但复传议美及走争高多办众研近分现。因确传每文大交该同农拉况叫在素什。布研院很场位结们见目千起件目。",
  19. "img": "http://dummyimage.com/200x200",
  20. "author": "阎勇",
  21. "dateTime": "2000年5月1日 22时11分42秒"
  22. },
  23. {
  24. "id": 3,
  25. "categoryid": 2,
  26. "title": "火列导人问叫志军油深非",
  27. "introduction": "铁真见组中即南电土会备定导们局局次叫需想完美作眼式再总青。",
  28. "content": "准说不做区求气亲始局山影到管代年。般今称平社结国我任且水展没华族本及。族发建水少会写半任活步任里使。整又入在响正新反和展联收院理往处。这开受他化多近却结难情被千百。",
  29. "img": "http://dummyimage.com/200x200",
  30. "author": "胡娜",
  31. "dateTime": "2002年8月6日 6时3分38秒"
  32. },
  33. {
  34. "id": 4,
  35. "categoryid": 3,
  36. "title": "外速流实层精建员你按我",
  37. "introduction": "值类高走层不见分族次好相为或前百代备基安下法正非况些总需七火。",
  38. "content": "及七根王断究六达量切军并西建地华。于导收究收证重区种大表己米广王。量点定层今格或经内电北马所南七们改车。般斯果打红快及人支适象满严。可较先量就物几这际流结难又级长你变。",
  39. "img": "http://dummyimage.com/200x200",
  40. "author": "杜芳",
  41. "dateTime": "1975年11月13日 16时53分21秒"
  42. },
  43. {
  44. "id": 5,
  45. "categoryid": 5,
  46. "title": "水的米组强人人构革矿",
  47. "introduction": "心构值九广即切当较体术每下进准自住国阶联质被白想北较。",
  48. "content": "产规斗住写而改被元料及全府革第团些。主实标众世问统约线和心派周所。角火素山消级王连万行强强水做系。却点种只天为话全至音属观业务。一难革你原积如三矿后段何表花。来交回消交验划按共积第式需。",
  49. "img": "http://dummyimage.com/200x200",
  50. "author": "顾敏",
  51. "dateTime": "2017年3月3日 18时40分8秒"
  52. },
  53. {
  54. "id": 6,
  55. "categoryid": 2,
  56. "title": "志元平队通发革小化近",
  57. "introduction": "特山各着县革如北个己书存通器下系道结际进党华心定。",
  58. "content": "文因名历联标工入别变及通清定阶。任说千斗近速军之四由治志斯动思况。节图区包起小加象以少感划民况白科消路。育书活团观周叫它面其第际织目。如来领次子该越京四务至济识没提种思必。",
  59. "img": "http://dummyimage.com/200x200",
  60. "author": "高娟",
  61. "dateTime": "1991年7月25日 17时0分46秒"
  62. },
  63. {
  64. "id": 7,
  65. "categoryid": 4,
  66. "title": "切委到至性资目百切所少因此所",
  67. "introduction": "查他民战斯识引资在儿制历们王马类因车见线越权时无。",
  68. "content": "资报界消声采点况很矿明八切收上国。每高列命正元方千区中老议存。自事反原候你电连近低实重只深水。美华小力最立金那过增府走角思精所会。近单为位压的叫高发即千党该果北。",
  69. "img": "http://dummyimage.com/200x200",
  70. "author": "史秀英",
  71. "dateTime": "1979年4月1日 4时53分56秒"
  72. },
  73. {
  74. "id": 8,
  75. "categoryid": 5,
  76. "title": "日心图月除见群进万治二",
  77. "introduction": "从到共却图克标热形以己打由条下设要圆子养度写结样。",
  78. "content": "感江验龙阶写联也部使求价值。严新斗会名律她标代光海权选克。八眼手传采断行专还价为面平意文选。例革济转专我历带品系工太角。",
  79. "img": "http://dummyimage.com/200x200",
  80. "author": "石敏",
  81. "dateTime": "2022年3月1日 20时13分34秒"
  82. },
  83. {
  84. "id": 9,
  85. "categoryid": 3,
  86. "title": "龙今影具思织集住族示行料做",
  87. "introduction": "被号走社团广大往近识如观则相间计自全改世革传。",
  88. "content": "形她省观称影府制非或从般比战位时非。十向革种改解风务无边派部学每然。用电回研元按适断局般八后常圆写三位就。你山许清去深发型日非员便来选容。",
  89. "img": "http://dummyimage.com/200x200",
  90. "author": "贺静",
  91. "dateTime": "1980年11月26日 23时59分17秒"
  92. },
  93. {
  94. "id": 10,
  95. "categoryid": 4,
  96. "title": "识务它之多走使电动安",
  97. "introduction": "照实形权律步么展心证日素保细江各间单往律历土。",
  98. "content": "思照设参题局去三亲少设节还。极明变他老极般却参形拉克表。要务流们改去按数调如太场东动联通形事。",
  99. "img": "http://dummyimage.com/200x200",
  100. "author": "林明",
  101. "dateTime": "1978年4月17日 19时5分24秒"
  102. }
  103. ]
  104. }
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post