莱农美食网
您的当前位置:首页vue+axios表单中上传图片步骤详解

vue+axios表单中上传图片步骤详解

来源:莱农美食网


这次给大家带来vue+axios表单中上传图片步骤详解,vue+axios表单中上传图片的注意事项有哪些,下面就是实战案例,一起来看一下。

然后问题就是element 中的上传控件在没有图片的时候是不会触发提交的,但接口写的是有file的 multipart/form-data 接收模式

所有只能自己另个模仿一个表单上传

<input class="file" name="file" type="file" accept="image/png,image/gif,image/jpeg" @change="update"/>
let file = e.target.files[0]; 
 let param = new FormData(); //创建form对象 
 param.append('file',file,file.name);//通过append向form对象添加数据 
 param.append('chunk','0');//添加form表单中其他数据 
 
 let config = { 
 headers:{'Content-Type':'multipart/form-data'} 
 }; //添加请求头 
 this.axios.post('http://upload.qiniu.com/',param,config) 
 .then(response=>{ 
 console.log(response.data); 
 })

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

在vue里使用axios步骤详解

axios+post方法提交formdata步骤详解

npm中install出现权限问题如何处理

显示全文