In a project where a large amount of data is needed to render the page, the back-end developer’s interface may not be written, and there is no back-end data support. We use mock.js to simulate fake data. The front and rear ends are separated. We can also use RAP2(where the generated data is based on mock.js) to simulate fake data online during development.
RAP2网 站 mock.js网 站 RAP2网 站 official document mock.js syntax specification document
Three, RAP2 use steps
- After entering RAP2 website account registration, we first create a project repository, as shown below:
- After the warehouse is built, we enter the warehouse and click New interface
- After the new interface is completed, we can see the following picture, we click the commodity list, the right picture can be set according to the request parameters, and the response content (click the green edit button), there is also an address in the right picture, click this address, enter the following content as shown in the picture
- Next, set request parameters and response parameters. Here, take response parameters as an example. Click “New” on the right of response content to create response properties, as shown in the picture below:
- Depending on the data type being created, the “+” sign shown in PIC_8 will appear on the left. Click the “+” sign to add attributes to its interior.
Figure PIC_8 shows the response data generated according to the filled generation rule. [There are 7 formats for generating rules, for which you can refer to the linked mock.js syntax specification document at the beginning of this article]. For example, the generation rule for the data attribute in the figure is 9, which means that 9 elements are generated. The id attribute is generated according to the rule 1-9999, which means random numbers from 1-9999 are generated.
- The methods on mock.random in the mock.js document are called “placeholders” in the data template and are written in the format of @ placeholders (parameters [, parameters]), which can be used in setting initial values to generate a random piece of content.
- Skip 5 and 6 if we want to define the data ourselves. According to different data types created, “+” as shown in PIC_8 will appear on the left side. Click “+” to add attributes to its interior and generate response data according to the filled generation rules.Note: If the data type is String, the custom data will not be executed. Generate rule +1, otherwise it will not be executed.
Ok, a simple simulation data is completed, we can try oh!