微信小程序打开预览PDF

iso打开没有下载,安卓打开有下载:

<view class='pdf_box' catchtap='downLoadPdf' data-url="https://baidu.pdf">
            <image src='../../images/pdf.png' mode='widthFix'></image>
            <label>下载资源</label>
</view>

JS:

  downLoadPdf(e){
    var url = e.currentTarget.dataset.url;
    wx.showToast({
      title: '打开中…',
      icon: "loading",
      duration: 100000
    })

  if (url){
    
    wx.downloadFile({
      url: url,
      header: {
        'content-type': 'application/json',
      },
      // filePath: wx.env.USER_DATA_PATH + "/res",
      success: function (res) {
        console.log(res)
        var Path = res.tempFilePath              //返回的文件临时地址,用于后面打开本地预览所用 
        wx.openDocument({
          filePath: Path,
          success: function (res) {          
              wx.hideToast();

          }
        })
      },
      fail: function (res) {
        console.log(res);
        wx.showToast({
          title: '下载失败',
          icon: "loading",
          duration: 1000
        })
      }
    })
  }
  
  },
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容