axios use :
1. In main.js introduced into axios module and axios added to Vue prototype object types :
// ES6 introduction module
axios from import 'axios'
// equivalent to const axios = require ( "axios" )
Vue.prototype.axios = axios;
2. Pit : Axios request default without the cookie ! Unusable server the session .
Solve : Configure Axios , allowed to carry the cookie :
axios.defaults.withCredentials=true
3. Pit : If Server using CORS cross-domain, can not accept the default authentication information
Server :
Installation cors module : NPM I -save cors
express main module app.js , the configuration cors middleware, allowed to receive authentication information:
app.use (air ({
origin:'http://localhost:8080',
credentials:true
}))
4. The call axios transmission request :
In any .vue in :
this.axios.get/post( ... )