axios如果请求需要使用multipart/form-data
类型
methods: {
handleSubmit() {
let formData = new FormData();
// 假设this.username和this.file是Vue组件中的数据属性
formData.append('username', this.username);
formData.append('file', this.file);
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then(response => {
// 处理成功响应
console.log(response.data);
})
.catch(error => {
// 处理错误
console.error('Error:', error);
});
}
}