使用uniapp提供给我们的uni.downloadFile、uni.saveFile和uni.openDocument三个API就可以了
也很简单,直接贴一下代码,安修修改一下即可
<template><view><image @tap="pdfDownLoad" style="width: 35rpx;height: 35rpx;" src="@/static/edit/pdf.png" mode=""></image></view>
</template>
<script>
export default {methods: {pdfDownLoad () {QualityUnitService.downLoadPdfById({ id: this.inputForm.qualityUnitFlowDTO.id }).then(({ data }) => {uni.downloadFile({url: '你的服务器地址' + data, // data是返回的文件路径success: res => {// uni.hideLoading()if (res.statusCode === 200) {uni.saveFile({tempFilePath: res.tempFilePath,success: red => {uni.showModal({title: '提示',content: '文件已保存:' + red.savedFilePath,cancelText: '知道了',confirmText: '打开文件',success: function (res) {if (res.confirm) {uni.openDocument({filePath: red.savedFilePath,success: (sus) => {console.log('成功打开');}})}}});}});} else {uni.showToast({title: '下载失败!',icon: 'none',duration: 800})}}})// download(this.serverUrl + res.data, null, s => {// console.log(s, 's--->>')// }, e => {// console.log(e, 'chucuo-->')// })})}}
}
</script>