微信小程序预览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