One. Project environment to build
1. Install node.js
2. Installation vue global and vue-cli
3. Create a project
vue create initialization program
4.npm run serve
To run the server template vue-cli
The configuration file vue.config.js
1 module.exports = { 2 devServer: { 3 port:8080, 4 host:"localhost", 5 https:false, 6 open:true 7 }, 8 lintOnSave:false, 9 productionSourceMap:false 10 }
6. integrate third-party libraries
npm i -S axios
Elevation and S-js PubSub
7. The mounting element-ui
Elevation and -S-element ui
The introduction of plug-in main.js in elementUI
Vue.use (elementUI) using plug-ins
Installation element UI snippets plugin to prompt elementUI grammar tips
8. Custom Packaging axios
By Axios send asynchronous requests, a package Axios object. Own package Axios subsequent use
axios interceptor provided.
In src create the directory utils directory and utils The following create request.js file
1 import axios from "axios" 2 const request=axios.create({ 3 baseURL:"/", 4 timeout:5000 5 }) 6 export default request
Custom response request interceptors and interceptors
1 // request interceptor 2 request.interceptors.requset.use (config => { . 3 // request interceptor . 4 return config . 5 }, error => { . 6 // abnormal . 7 return Promise.reject (error) . 8 }) 9 // response blocker 10 request.interceptors.response.use (response => { . 11 return response 12 is }, error => { 13 is return Promise.reject (error) 14 }) 15 request.get("'./db.json").then(response=>{ 16 console.log(response.data) 17 })