微信小程序实现文件预览
更新时间:2020年10月22日 16:59:57 作者:xiaoyanyanlh
这篇文章主要为大家详细介绍了微信小程序实现文件预览,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
微信小程序的文件预览,供大家参考,具体内容如下
微信小程序的文件预览需要先使用wx.downloadFile下载文件,然后使用下载文件的临时路径通过wx.openDocument进行文件的
预览
wxml代码:
<button bindtap='preview'>简历预览</button>
js代码:
//简历预览 preview: function () { var that = this; console.log("简历预览") //这里的value是先在data里面初始化,然后我根据用户切换单选框,获取的简历文件的主键id console.log(this.data.value) var id = that.data.value; if (id == "") { wx.showModal({ title: '', content: '请选择一份简历', showCancel: false, confirmColor: "#FFB100" }) } else { //先通过简历的主键id,查询简历路径(大家可以根据自己的需求来传数据) wx.request({ url: app.globalData.url + "/api/interview/queryFilePath", data: { id: id }, method: 'POST', header: { "content-type": "application/x-www-form-urlencoded" }, success: function (res) { console.log(res.data) that.setData({ path: res.data.path, type: res.data.type }) //下载简历 wx.downloadFile({ url: app.globalData.url + that.data.path, success: function (res) { var filePath = res.tempFilePath console.log(filePath) //预览简历 wx.openDocument({ filePath: filePath, fileType: that.data.type, success: function (res) { console.log("打开文档成功") console.log(res); }, fail: function (res) { console.log("fail"); console.log(res) }, complete: function (res) { console.log("complete"); console.log(res) } }) }, fail: function (res) { console.log('fail') console.log(res) }, complete: function (res) { console.log('complete') console.log(res) } }) } }) } },
为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
微信小程序scroll-view横向滑动嵌套for循环的示例代码
这篇文章主要介绍了微信小程序scroll-view横向滑动嵌套for循环的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-09-09JavaScript中统计Textarea字数并提示还能输入的字符
是在文本框中输入文字的时候,会自动统计输入的字符,并显示用户还能输入的字符,其实js也可以实现,下面就以示例的方式为大家讲解下2014-06-06JavaScript限制在客户区可见范围的拖拽(解决scrollLeft和scrollTop的问题)(2)
这篇文章主要介绍了JavaScript限制在客户区可见范围的拖拽,解决scrollLeft和scrollTop的问题,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-05-05
最新评论