vue 项目中使用原生 input type="file" 上传图片

vue 项目中使用 原生 input  type=“file” 上传图片

//html 代码
<input type="file" @change="uploadImg" accept="image/*" />
//js 代码
uploadImg:function(e){

let that = this;
let file = e.target.files[0];
let formData = new FormData();//创建 formdata对象
formData.append('file',file);
this.$axios.post(
url,
formdata,
{headers:{ 'Content-Type':'multipart/form-data' }})
.then(res=>{
console.log(res,'upolad img')
}).catch(err=>{})
}

猜你喜欢

转载自www.cnblogs.com/sunnyeve/p/12760288.html