Vue Pits (ii) Let Axios send form form data

Source: Internet
Author: User

(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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.