wx.downloadFile(OBJECT)下载文件资源到本地,客户端直接发起一个 HTTP GET 请求,返回文件的本地临时路径。wx.openDocument(OBJECT)新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。附上 api文档
fileInfo: function(e) {
var that = this;
that.setData({
loadingHidden: false
})
var url = e.currentTarget.dataset.url;
wx.downloadFile({
url: 'https://xxx.com' + url,
success: function(res) {
var filePath = res.tempFilePath;
wx.openDocument({
filePath: filePath,
success: function(res) {
//页面显示加载动画
that.setData({
loadingHidden: true
})
console.log('打开文档成功')
}
})
},
})
},
<block wx:for="{{list}}" wx:key="index">
<view class='fileList' bindtap='fileInfo' data-url='{{item.f_url}}'>下载文件</view>
</block>
<loading hidden="{{ loadingHidden }}">加载中...</loading>