How to call simulated data in Vue Framework
This article mainly explains "how to call simulation data in Vue framework". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to call simulation data in Vue framework".
1. Frame structure
Mock is the simulation data folder, which contains index.js, which contains the simulated interface data: as follows
Const Mock = require ("mockjs"); const {param2Obj} = require (". / utils"); const user = require (". / user"); / / call mode const mocks = [. User]; function mockXHR () {/ mock patch / / https://github.com/nuysoft/Mock/issues/300 Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send Mock.XHR.prototype.send = function () {if (this.custom.xhr) {this.custom.xhr.withCredentials = this.withCredentials | | false; if (this.responseType) {this.custom.xhr.responseType = this.responseType;}} this.proxy_send (.minutes);} Function XHR2ExpressReqWrap (respond) {return function (options) {let result = null; if (respond instanceof Function) {const {body, type, url} = options / / https://expressjs.com/en/4x/api.html#req result = respond ({method: type, body: JSON.parse (body), query: param2Obj (url),});} else {result = respond } return Mock.mock (result);};} for (const i of mocks) {Mock.mock (new RegExp (i.url), i.type | | "get", XHR2ExpressReqWrap (i.response));} module.exports = {mocks, mockXHR,}
2. Call in api: as shown in the figure
Then you can successfully request the data.
At this point, I believe you have a deeper understanding of "how to call simulation data in the Vue framework". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!