This article mainly introduces how to build a front-end independent development environment with Vue Mock.js. 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 a Mock in the same directory as main.js. 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 intercept according to the Mockjs document Ajax request returns simulated data. As for how to do it, just read the documentation. 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 you. Everyone’s learning is helpful. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Introduction to creating quick-shell.js library
vue-router nginx non-root path Configuration method
The above is the detailed content of How to build a front-end independent development environment with Vue+Mock.js. For more information, please follow other related articles on the PHP Chinese website!