<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); } }) },