vue前后端分离,使用element的el-button组件从后台下载文件,并且解决乱码问题
1.添加下载按钮
2.(更正版)用axios({})这种方式,配置参数
this.$axios({
method: "POST",
url: "/api/image_down",
responseType: "blob",
data: that.qs.stringify({
get_id: that.cy_id,
}),
}).then((res) => {
if (response.data.size === 0) {
console.log('下载失败')
} else {
this.downloadFile(res.data);
}
}).catch((error) => this.$message.error(error));
downloadFile(data) {
let blob = new Blob([data], { type: "application/zip" });
l