微信小程序預覽Word文檔


<view data-url="https://xxxcom/attachment/word.docx" data-type="docx" catchtap='downloadFile' >word.docx</view>

js文件

downloadFile: function (e) {
    var that = this;
    var filePath = e.currentTarget.dataset.url;//對應的網絡路徑,可以是內網的或者外網
    var fileType = e.currentTarget.dataset.type; 
    wx.downloadFile({//下載對應文件
      url: filePath,
      success: function (res) {    
        var filePath = res.tempFilePath;//文件路徑    
        wx.openDocument({
          filePath: filePath,   // 裝載對應文件的路徑
          fileType: fileType,   // 指定打開的文件類型
          showMenu: true,       // 右上角的菜單轉發分享操作
          success: function (res) {
            console.log("打開成功");
          },
          fail: function (res) {
            console.log(res);
          }
        })   
      },
      fail: function (res) {
        console.log(res);
      }
    })       
},

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM