.wxml文件代码
<view class='control'>
<view bindtap='loadDown'>查看</view>
</view>
.js文件代码
//点击查看文件
loadDown: function(e) {
var that = this;
//下载文件
wx.downloadFile({
url: url(你自己的接口路径,跟一般的接口请求路径是一样的,有参数在后面加,类似:?id=123456),
success: function(result) {
console.log(result);
//拿到临时缓存路径
var filePath = result.tempFilePath;
//打开已下载好的文件
wx.openDocument({
filePath: filePath,
success: function(respone) {
console.log('打开成功')
},
fail:function(res){
app.msg('打开失败')
}
})
},
fail: function(res) {
app.msg('下载失败')
},
})
},