用 Axios 上传文件的几种方式
var formData = new FormData();
var imagefile = document.querySelector('#file');
formData.append("image", imagefile.files[0]);
axios.post('upload_file', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
var formData = new FormData();
formData.append("image", imagefile.files[0]);
export function uploadFile(data: any) {
return axios({
url: '/upload',
method: 'post',
data
});
}
uploadFile(formData)