Axios is the official recommended HTTP request tool for vue2.0, before the Vue-resource
Two ways of using it are summarized in the process:
1. Use similar with Vue-resource
Introduced:import axios from ‘axios‘;
Vue.prototype.$http = axios;
Use:this.$http.get(URL).then(response => { // success callback }, response => { // error callback });
2. Use in the components you need
introduced: import Axios from ' Axios ';
use: < Span class= "Hljs-keyword" > axios
. Get (URL). Then (< Span class= "Hljs-params" >response = {//success Callback}, response = {//Error callback });
Note: Assigning the response return value to data is not always successful, the previous code:
axios.get ()
if (Response.data.errno = = = Err_ok) {
Span style= "COLOR: #736f5c" > This.seller = Response.data.data;
}
Console.log (response.data.data);
})
. catch (function (error) {
Console.log (error);
});
Now instead of the ES6 syntax specification, now the code:
Axios. Get ('/api/seller '). Then (response = {
if (Response.data.errno = = = Err_ok) {
This.seller = Response.data.data;
}
}, Response = {
Console.log (response);
});
Using Axios in Vue.js