react-mockjs

2020-01-17

react-mockjs use

Recently participated in a new project company, while the front and back end development, back-end can not at this time provide front-end interface, then it is up to our own front-end data mock it.

Tools used in mock data is mockjs, is this.

 

 

 Here is the github Address: https://github.com/nuysoft/Mock/wiki/Getting-Started

 

# Install 
npm install mockjs

 

# 导入 mockjs
import mockjs from 'mockjs';

 

Proxy = const { 'GET / API / getUser ': (REQ, RES) => res.send (mockjs.mock ({    // / API / getUser is the interface name I need to access the
     "code": 0 ,
     " Content | 1 " : [{     // content | 1 content is the data I eventually want to get 1 refers to generate a content  
       " The above mentioned id | +1 ": 1 ,
" name ": " @cname " ,
" the Job | 1 ": [ "front-end engineer", "front-end assistant", "front-end experts" and "operation and maintenance experts", "back-end engineers " ],
" jobNum |. 1 ": [. 1, 12 is, 34 is, 56 is, 23 is, 45, 56 is, 34 is, 56 is, 77,. 4, 321, 443, 654, 231 ],
" DATE ":" @date " ,
" jobHour ": " @integer " ,
  }],
 Success:
to true ,
Message:
'123' ,
})) }
export default delay(proxy, 1000);
 

 

mockjs 有很多方便之处,它的规范和用法官网写的很清楚,去官网看哦

1、安装:https://github.com/nuysoft/Mock/wiki/Getting-Started

2、规范:https://github.com/nuysoft/Mock/wiki/Syntax-Specification

3、占位符@XXX规范:https://github.com/nuysoft/Mock/wiki/Mock.Random

4、炒鸡全面的示例:http://mockjs.com/examples.html

5、一个很详细的解释:https://www.jianshu.com/p/9dbcfbe6130f

Guess you like

Origin www.cnblogs.com/fengwenya/p/12205761.html