小程序下载文档到本地预览

it2025-10-17  7

小程序下载文档到本地预览 做小程序项目时:需要预览pdf文件,如果是某个在线文档,需要配置文档的业务域名才能打开

var that = this; wx.downloadFile({ url: url,//要预览的地址 // header:{ // 'Refer-Ssc':api.getRefer() // }, success: function (res) { if (res.statusCode === 200) { //成功 var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用 wx.openDocument({ filePath: Path, //要打开的文件路径 showMenu: true, success: function (res) { that.setData({ file1: Path //file1在data中自行定义 }) api.hideLoading() }, fali() { api.showModal('文件打开失败,请联系管理员') } }) } }, fail: function (res) { api.showModal('文件打开失败,请联系管理员') } })
最新回复(0)