vue用axios上传文件
1.post 请求头改成'Content-Type':'multipart/form-data'2.用new FormData() 方式//上传export function uploadFile(data) {return request({url: '/appstore/uploadFile',method: 'post',headers: {'Content-Type':'multipart
·
1.post 请求头改成'Content-Type': 'multipart/form-data'
2.用new FormData() 方式
//上传
export function uploadFile(data) {
return request({
url: '/appstore/uploadFile',
method: 'post',
headers: {'Content-Type': 'multipart/form-data'},
data: data
})
}
var file = e.target.files[0];
let param = new FormData();
param.append('fileType','img')
param.append('file',file)
uploadFile(param).then(response => {
if (response.code === 200) {
console.log(response)
that.Form.appLogoUrl=response.filePath;
} else {
console.log("上传错误")
}
});
更多推荐
已为社区贡献1条内容
所有评论(0)