admin管理员组文章数量:1530048
1.定义下载点击事件
<view class="button">
<view class="submit" @click="download(lawInfo.Enclosure)"><text>下 载</text></view>
</view>
//下载文件
download(e) {
let that = this
uni.downloadFile({
url: imghost+'/StaticFiles'+ e , //下载地址,后端接口获取的链接
success: (data) => {
console.log(data.tempFilePath)
console.log(JSON.stringify(data))
if (data.statusCode === 200) {
uni.saveFile({ //文件保存到本地
tempFilePath: data.tempFilePath, //临时路径
success: function(res) {
console.log("下载成功"+res.savedFilePath)
console.log(JSON.stringify(res))
uni.showToast({
icon: 'none',
mask: true,
title: '文件已保存!',
duration: 3000,
});
uni.openDocument({
fileType: 'docx',
filePath: res.savedFilePath,
success: function(res) {
console.log('打开文档成功');
}
});
}
});
}
},
fail: (err) => {
console.log(err);
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载',
});
},
});
},
2.注意ios下载不能为空文件
3.ios小程序只能打开docx,xlsx,pptx等类型的文件
版权声明:本文标题:uniapp下载文件 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726629701a1079075.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论