The sole purpose of using MOCKJS is to quickly complete the front-end project, and the front end does not need to wait for the backend data, use mock, to simulate it ~
It can intercept AJAX requests and simulate the return of the data you need. This is the real front-end separation.
Okay, here's the beginning of the actual combat.
Install first
NPM Install MOCKJS--save-dev
New Data.js (Analog data)
Import Mock from ' mockjs '= mock.mock ({ "data|0-3": [ "Zhejiang A12222", ]}); Export {Data}
New Mock.js introduces data and intercepts requests
Import Mock from ' Mockjs'./data/data '; Mock.mock ('/do ', ' post ', data);
Build Api.js Package Axios Request
Import Axios from ' Axios 'Import Vue from' Vue 'axios.defaults.headers= {"Content-type": "application/x-www-form-urlencoded"}functionfetch (URL, params) {return NewPromise (Resolve, reject) ={axios.post (URL, params). Then (response={Resolve (Response.data); }) .Catch(Error) ={reject (Error); })})} Exportdefault{getplate (URL, params) {returnfetch (URL, params); },}
And then call in the Vue component.
Api.getplate ('/do ', content) = { allplate = Res.data;})
Note the request address in the build should be the same as the address in mock.js.
You can also look at the Axios-mock-adapter, talk about Axios and Vue combination, should be better use a little.
Mockjs+vue Use of small notes