Use of Mockjs and Vconsole in VUE-CLI projects

Source: Internet
Author: User

Mockjs use

1. Installing NPM Install MOCKJS

2. Create a Util folder in the Src/assets directory and a new file in it Mock.js

For example:

Const MOCK = require (' MOCKJS ')
Const RANDOM = Mock.random

Export default Mock.mock (' Api/mocktest ', createdata)
function Createdata () {
let articles = []
for (Let i = 0; i < 9; i++) {
Let Newarticleobject = {




}
Articles.push (Newarticleobject)
}
return {
Articles:articles
}
}
3. References, can globally reference require ('./assets/util/mock.js ') in Main.js
4. Using in the Vue component
Axios.get (' Api/mocktest '). Then (res =
This.items = Res.data.articles
Console.log (Res.data.articles)
})
Vconsole use

1. Installing NPM Install Vconsole

2. Create a Util folder in the Src/assets directory and a new file in it Vconsole.js

For example:

Import vconsole from ' Vconsole '
Let Vconsole = new Vconsole ()
Export Default Vconsole

3. References, can globally reference require ('./assets/util/vconsole.js ') in Main.js

4. The Vconsole control appears on the Startup project page

5. Principle

(1) Override console

(2) Capturing and reporting JS errors with Window.onerror

Use of Mockjs and Vconsole in VUE-CLI projects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.