Install the command NPM install mockjs

Official documents http://mockjs.com/

1. Quick use

Mock ({// The value of the property list is an array of 1 to 10 elements"list|1-10"// The attribute id is an increment starting from 1 and incrementing by 1 each time"id|+1": 1}]}); console.log(data); console.log(Mock.Random.cname());Copy the code

2. Expand your own placeholders

// Extend the placeholder mock.random.extend ({cstore() {       return this.pick([         "Pet Shop"."Beauty shop"."Snack bar"."Digital Store"."Fast-food restaurant"."Ha ha Shop"]); }}); console.log(Mock.mock("@cstore"));Copy the code

3. Mock and generate random data

Import axios from “axios” in a single page

var Mock = require("mockjs");    axios      .get(        "http://113.141.174.129:88/jeecg-boot/smgr/autoDivideClass/getAcademicYearListInfos") .then(res => { console.log(res); }); // Use mock intercept and randomly generate data mock. mock("http://113.141.174.129:88/jeecg-boot/smgr/autoDivideClass/getAcademicYearListInfos",      {        "list|5-10": [{"id|+1": 1,            name: "@cname",            email: "@email"}}]);Copy the code

Mock interception, where the URL must match the AXIOS request URL