小程序中PDF文件预览问题
在小程序中可以ios端可以使用 <web-view :src="url"></web-view>
但是在Android端pdf文件会自动下载
解决方案:1 通过判断 系统类型是否是ios还是Android,如果是ios端使用<web-view :src="url"></web-view>进行预览
如果是Android 使用小程序文件上传预览方法
// pdf功能预览
openMaterial(url) {
wx.getSystemInfo({
success: function(res) {
console.log(res.system);
if (res.system.indexOf("Android") != -1) {
wx.downloadFile({
url: url,
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);
}
});
} else if (res.system.indexOf("iOS") != -1) {
wx.navigateTo({
url: "/pages/search/main?url=" + url
});
}
}
});
}