方法一
web-view下,可以直接通过a标签设置src
(注:个人类型的小程序暂不支持使用)
<a href="https://xxx.pdf" style="color: red;">查看</a>
1、必须是以https开头,http在小程序中无法打开;
2、需要在小程序中设置好业务域名
3、ios可以直接打开预览,安卓必须先下载才能查看。
方法二
使用小程序文件下载和预览API
(注:web-view下暂不支持此API)
wx.downloadFile({
url: id ,
success: function (res) {
console.log(res)
var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
wx.openDocument({
filePath: Path,
success: function (res) {
console.log('打开成功');
}
})
},
fail: function (res) {
console.log(res);
}
})