MOCKJS is a common tool for front-end analog HTTP request and reply, which can simulate various HTTP requests and return results. The front-end simulation of the backend interface is implemented in the case of no-end. Mock basic use is also relatively simple, this article we mainly share with you mock.js interception HTTP request instance resolution, hope to help everyone.
However, when the MOCKJS is introduced,
import Mock from ‘mockjs‘
Intercepts HTTP requests from all front ends, intercepting HTTP requests regardless of whether the mock emulation is turned on using Mock.mock.
This is why, even if not mock.mock, the backend cannot get the front-end HTTP request.
Therefore, once the MOCKJS is referenced, the HTTP request cannot be made through the front-end and will be intercepted by MOCKJS
You need to remove the reference to MOCKJS before the NPM run build.
References to a mock in the dev environment and release environment
import global from ‘../src/common/global‘;if (global.env === ‘dev‘){ var Mock = require(‘mockjs‘);}if (global.env === ‘dev‘){ //Run MOCK for (let mockData of mockDatas){ //console.log(mockData); Mock.mock(mockData.url, mockData.data); }}
global.env = = = ' Dev ' in the dev development environment, introducing MOCKJS to avoid real HTTP requests being intercepted in release releases.
The global config variable is custom, not a global variable.
Mock.js Blocking HTTP request issues
MOCKJS is a common tool for front-end analog HTTP request and reply, which can simulate various HTTP requests and return results. The front-end simulation of the backend interface is implemented in the case of no-end. The basic use of Mock is also relatively simple: Mock.js official website
However, when the MOCKJS is introduced,
import Mock from ‘mockjs‘
Intercepts HTTP requests from all front ends, intercepting HTTP requests regardless of whether the mock emulation is turned on using Mock.mock.
This is why, even if not mock.mock, the backend cannot get the front-end HTTP request.
Therefore, once the MOCKJS is referenced, the HTTP request cannot be made through the front-end and will be intercepted by MOCKJS
You need to remove the reference to MOCKJS before the NPM run build.
References to a mock in the dev environment and release environment
import global from ‘../src/common/global‘;if (global.env === ‘dev‘){ var Mock = require(‘mockjs‘);}if (global.env === ‘dev‘){ //Run MOCK for (let mockData of mockDatas){ //console.log(mockData); Mock.mock(mockData.url, mockData.data); }}
global.env = = = ' Dev ' in the dev development environment, introducing MOCKJS to avoid real HTTP requests being intercepted in release releases.
The global config variable is custom, not a global variable.
In this share of the months I do the cylindrical wood template industry website: http://zhimo.yuanzhumuban.cc/
Mock.js intercepting HTTP Request Instance parsing-JS notes