使用uni.downloadFile() 方法下载文件 并在微信本地预览 再使用uni.openDocument() 新页面打开文档
uni.downloadFile({
url: fileUrl, //下载地址接口返回
filePath: wx.env.USER_DATA_PATH + "/" + fileName,
success: (data) => {
if (data.statusCode === 200) {
uni.hideLoading();
//文件预览
var filePath = data.filePath;
uni.openDocument({
//新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。
filePath: filePath,
showMenu: true,
success: function(res) {},
});
}
},
});