(i) using Axios Vue-axios QS
1.qs is an essential plug-in
NPM Install--save Axios vue-axios QS
2. After the installation is complete, insert the following code in the Main.js
Load Axios
Import qs from ' QS '
Import Axios from ' Axios '
Import Vueaxios from ' Vue-axios '
var axios_instance = axios.create ({
BaseURL: ' http://localhost ',//modify the URL yourself
Transformrequest: [function (data) {
data = qs.stringify (data);
return data;
}],
headers:{' content-type ': ' application/x-www-form-urlencoded '}
})
Vue.use (Vueaxios, axios_instance)
3. This can be used in the Vue module
this. $http. Post (' url ', {
Id:1
}). Then (response = {
Console.log (response)
}). catch (Error = =
Console.log (Error);
});
Two
1. Installing Axios
NPM Install Axios--save 2. Insert the following code in Main.js import Axios from ' axios ' Axios.defaults.baseURL = ' http://localhost:xxx/api/'; Vue.prototype. $http = Axios; 3. Axios used in Components
with no parameters:this. $http. Post (' Tablelist/tableload '). Then (response = {}, response = {})
upload data in formdata form:Let FD = new FormData (); Fd.append (' file ', file);//upload here is a picture file to Base64 pass this. $http. Post (' Fileupload/fileupload ', fd,{headers:{' content-t Ype ': ' Multipart/form-data '//hearder is important, content-type to write to}}. Then (response = {}}, response = {})
Vue Pits (ii) Let Axios send form form data