1. Download mock.js and install it in your project

The operation is as follows:

  • 1: Yarn add mockJS in the YARN environment
  • 2: npm

    npm install mockjs

2. Set the parameters in mian

if (process.env.NODE_ENV === 'development') {
  require('./mock')}Copy the code

Create folders named Mock and index.js in the same directory as main.js

4. The configuration is as follows

import Mock from 'mockjs'

Mock.setup({
  timeout: '200-600' // The interval between requests and responses
})

// Define a function that takes a URL and other things
const mockr = (url, teml) = > Mock.mock(new RegExp(url), teml);
[
 // The array defines mock formats, such as:
  [
    '/doorcontrol/attendreport/exportUserAttendCollectList', {"code": 200."msg": "success"."data": "192.168.1.71:9020 / import/user / 0 / attendance summary report 1582869379125. XLS"
    }
  ],
].forEach(item= > {
  // Loop through the array and call that function
  mockr(item[0], item[1])})Copy the code

5. Explanations are as follows

When mocks are used, the mock is searched for the configured strength when the request is made, the mock is used to request it, and the data is returned