vue项目图片上传 vant van-uploader 图片上传
vant van-uploader 图片上传
<van-uploader accept="image/*" v-model="fileList" multiple :after-read="afterRead"></van-uploader>
afterRead: function(file) {
if (this.fileList.length > 3) {
this.$toast.fail("图片上传最多三张!");
this.fileList.splice(3);
return;
}
let formData = new FormData();
formData.append("file", file.file);
this.$api.shopOrdersReturnUpload(formData).then(res => {
if (!res.success) {
this.$toast.fail("图片上传失败,请重新上传!");
return;
}
if (res.data) {
this.$toast.success("图片成功!");
this.fileList[this.fileList.length - 1].r_path = res.data.r_path;
}
});
},
重点 axios
http.interceptors.request.use(
(config) => {
config.headers['Content-Type'] = 'multipart/form-data';
},
error =>
Promise.reject(error)
)