美文网首页前端之路
微信小程序预览文档

微信小程序预览文档

作者: 择一城终老_3069 | 来源:发表于2019-07-11 13:12 被阅读0次

    场景:需要小程序内打开预览文档
    1.首先想到的是下载----->打开 所以选用了downloadFile----->openDocument 然而问题来了。iPhone会出现打不开的情况,监测了下方法执行没问题都是success
    2.查文档,换套路,选用新标签web-view ,Android不支持
    3.最终解决方案:如下

    wx.getSystemInfo({
          success: function(res) {
            console.log(res.model)
            var string = res.model;
            if (string.indexOf("iPhone") >= 0) {
              //苹果手机
            // ===>  <web-view src="{{url}}"></web-view>
            }else{
              wx.downloadFile({
                url: that.data.ResumeInfo.word_resume, //仅为示例,并非真实的资源
                success(res) {
                  if (res.statusCode === 200) {
                    var Path = res.tempFilePath
                    wx.openDocument({
                      filePath: Path,
                      success: function (res) {
                      }
                    })
                  }
                }
              })
            }
          },
        })
    

    相关文章

      网友评论

        本文标题:微信小程序预览文档

        本文链接:https://www.haomeiwen.com/subject/eljkkctx.html