Below I will share with you an article about axios sending post request and submitting image type form data method. It has a good reference value and I hope it will be helpful to everyone.
DOME
<input type="file" @change="upload" ref="upload">
Interface
const userUploadAtt = (File,config) => axios.post("接口",File,config)
Processing data
let input = this.$refs.upload 创建一个空的FormData对象 let data = new FormData(); 使用FormData.append来添加键/值对到表单里面; 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请求时候表单上传不需要引入qs.stringify()
The above is what I compiled for everyone , I hope it will be helpful to everyone in the future.
Related articles:
About the difference between v-if and v-show in vuejs and the problem that v-show does not work
Using iview to customize the verification keyword input box in vue Problems and solutions
The problem of adding expressions to v-show in Vue (determining whether to display)
The above is the detailed content of axios sends a post request and submits image type form data method. For more information, please follow other related articles on the PHP Chinese website!