前端发送请求上传文件使用formData提交

var file = this.$refs.fileId.files[0];
let formData = new FormData();
formData.append("file",file);
formData.append("content",content);
that.$axios.post(
     url,
     formData
).then(function(response) {
     that.$message.success('上传成功');
}) .catch(function(error) {
     that.$message.error(res.data.msg);
});

//前台提交后文件是以二进制文件流的形式传到后台
数据统一放在FormData中传递到后台

 

posted @ 2021-05-17 10:51  氧化成风  阅读(664)  评论(0)    收藏  举报