流程【后台】 详情看若依框架
axios 请求配置
npm install file-saver // 安装依赖
文件utils/request.js
axios -----> responseType: 'blob', 二进制
`responseType` 表示服务器响应的数据类型
this.download(
"api", // api接口
{
id, // post 请求参数
},
`order_${new Date().getTime()}.xlsx` // 导出默认文件名+后缀
// 注意: windows自带的excel打不开xlsx文件,需要改成xls
);
uniapp小程序
uni.downloadFile({
// 下载文件
url: "ur资源地址", // 后端接口返回
success(res) {
// console.log('下载成功',res);
uni.openDocument({
// 新开页面打开文档
filePath: res.tempFilePath,
showMenu: true,
success: function (res) {
// console.log('打开文档成功',res);
},
fail(err) {
uni.showToast({
title: "打开文档失败",
icon: "none",
});
},
});
},
fail(err) {
uni.showToast({
title: "下载失败",
icon: "none",
});
},
});