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

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

不言
Release: 2018-07-14 09:19:05
Original
1959 people have browsed it

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

  1. Install Mock

    npm i mockjs -s

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

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')
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 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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!