在微信小程序中使用uni-app预览pdf文件
在之前的项目中,有一个是需要使用在H5中预览pdf文件,当时使用了hybrid来预览,
现在是需要一套程序,两处使用,因此下边将会展示小程序中预览文件
// #ifdef MP */ 是区分运行的环境,在小程序中可使用如下方法 uni.downloadFile({ url: item.link,//文件地址 success: function (res) { var filePath = res.tempFilePath; uni.openDocument({ filePath: filePath, showMenu: false, //这个参数可设置你预览的文件能否被直接转发,此次是设置是否展示分享菜单 success: function (res) { } }); } }); /* #endif */ /* #ifdef H5 */ //这里是H5中的写法 uni.navigateTo({ url: '/pages/index/pdfview?url='+item.link+'', }) /* #endif */
根据以上代码,即可在使用uni-app开发的小程序中预览文件

浙公网安备 33010602011771号