uniapp开发的移动端页面在ios中可以正常使用uni.downloadFile获取临时地址然后用a标签下载(很抱歉造成困扰,微信浏览器不能下载文件保存到本地,可查看转发用其他软件打开操作),安卓在微信浏览器不行。
uni.downloadFile({
method: 'GET',
url: this.working_template,
header: {},
success: (res) => {
if (res.statusCode === 200) {
if (uni.getSystemInfoSync().platform === 'android') {
var oA = document.createElement("a");
oA.download = '111';
oA.href = this.working_template;
document.body.appendChild(oA);
oA.click();
oA.remove();
} else {
var oA = document.createElement("a");
oA.download = '破文件';
oA.href = res.tempFilePath;
document.body.appendChild(oA);
oA.click();
oA.remove();
}
}
},
fail: (err) => {
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载',
});
}
})