微信小程序如何实现文件预览

  介绍

微信小程序如何实现文件预览?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

微信小程序的文件预览需要先使用wx.downloadFile下载文件,然后使用下载文件的临时路径通过wx。openDocument进行文件的

预览

wxml代码:

& lt;按钮bindtap=& # 39;预览# 39;在简历预览& lt;/button>

js代码:

//简历预览
  预览:函数(){
  var=这个;
  console.log(“简历预览“)//这里的价值是先在数据里面初始化,然后我根据用户切换单选框,获取的简历文件的主键id
  console.log (this.data.value)
  var id=that.data.value;
  
  如果(id==啊? {
  wx.showModal ({
  标题:& # 39;& # 39;
  内容:& # 39;请选择一份简历& # 39;,
  showCancel:假的,
  confirmColor:“# FFB100"
  })
  其他}{//先通过简历的主键id、查询简历路径(大家可以根据自己的需求来传数据)
  wx.request ({
  url: app.globalData。url +“/api/面试/queryFilePath"
  数据:{
  id: id
  },
  方法:& # 39;文章# 39;
  标题:{“content-type":“应用程序/x-www-form-urlencoded"},
  成功:函数(res) {
  console.log (res.data)
  that.setData ({
  路径:res.data.path,
  类型:res.data.type
  })//下载简历
  wx.downloadFile ({
  url: app.globalData。url + that.data.path,
  成功:函数(res) {
  var filePath=res.tempFilePath
  console.log (filePath)//预览简历
  wx.openDocument ({
  filePath: filePath,
  文件类型:that.data.type,
  成功:函数(res) {
  console.log(“打开文档成功“)
  console.log (res);
  },
  失败:函数(res) {
  console.log (“fail");
  console.log (res)
  },
  完成:函数(res) {
  console.log (“complete");
  console.log (res)
  }
  })
  },
  失败:函数(res) {
  console.log(& # 39;失败# 39;)
  console.log (res)
  },
  完成:函数(res) {
  console.log(& # 39;不能# 39;)
  console.log (res)
  }
  })
  }
  })
  }
  },

关于微信小程序如何实现文件预览问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。

微信小程序如何实现文件预览