Home > Web Front-end > JS Tutorial > body text

How to build a front-end independent development environment with Vue+Mock.js

不言
Release: 2018-07-11 15:55:20
Original
1435 people have browsed it

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

  1. Install Mock

    npm i mockjs -s

  2. 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'
  })
})
Copy after login

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')
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template