This article mainly introduces how to use Vue Mock.js to build a front-end independent development environment. It has certain reference value. Now I share it with you. Friends in need can refer to it
Install Mock
npm i mockjs -s
Create Mock file
Create it in the same directory as main.js A Mock.js (you can name it arbitrarily) is used to store our data deception code
Mock.js
const Mock = require('mockjs') Mock.mock('/register', function (options) { console.log(options) return Mock.mock({ 'number': '1' }) })
In this file, we can use Mockjs according to the Document to intercept ajax requests and return simulated data. As for how to do it, just read the document. It is quite simple.
3. Introduce the data that needs to be simulated in main.js
main.js
require('./mock')
4. This is the configuration. Send the request as usual on the page where the request needs to be sent. Mock.js will automatically intercept the request and return the data we set
The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Vue2.0 custom instructions and instance properties and methods
How to use NodeJS Lighthouse Gulp Tools for building automated website performance testing
The above is the detailed content of How to use Vue+Mock.js to build a front-end independent development environment. For more information, please follow other related articles on the PHP Chinese website!