mpvue PDF文件預覽

小程序中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
            });
          }
        }
      });
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章