Axios sends a post request and submits the image type form data method,
DOME
<Input type = "file" @ change = "upload" ref = "upload">
Interface
Const userUploadAtt = (File, config) => axios. post ("interface", File, config)
Process Data
Let input = this. $ refs. upload creates an empty FormData object let data = new FormData (); Use FormData. append to add key/value pairs to the form; data. append ('file', input. files [0]); upload () {userUploadAtt (data, {headers: {'content-type': 'multipart/form-data '}}). then (response) => {this. headPhoto = response. data [0]. msg. url ;}). catch () => {})}
Note:
If
Axios. defaults. headers. post ['content-type'] = 'application/x-www-form-urlencoded; charset = UTF-8 'Post request when form upload does not need to introduce qs. stringify ()
In the above post request sent by axios, the method for submitting image form data is all the content shared by Alibaba Cloud xiaobian. I hope you can provide a reference and support for the customer's house.