欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

微信小程序下载并打开附件

程序员文章站 2022-06-25 12:15:45
download(e) { let t = this; $.showloading() wx.downloadFile({ url: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1591007826562&di=c6d5dfb0816ec0bffb2d0bd9ee33a7ec&imgtype=0&src=http%3A%2F%2Fn...
download(e) {
    let t = this;
    $.showloading()
    wx.downloadFile({
      url: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1591007826562&di=c6d5dfb0816ec0bffb2d0bd9ee33a7ec&imgtype=0&src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn01%2F173%2Fw580h393%2F20180417%2Ff585-fzcyxmv6432698.jpg',
      success: function (res) {
        console.log(res);
        $.hideloading();
        var filePath = res.tempFilePath;
        console.log(filePath);
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log(res)
          },
          fail: function (res) {
            console.log(res);
          },
          complete: function (res) {
            console.log(res);
          }
        })
      },
      fail: function (res) {
        $.toast("文件下载失败")
        setTimeout(() => {
          $.hideloading();
        }, 2000)
      },
      complete: function (res) {},
    })
  }

本文地址:https://blog.csdn.net/WangYi0118/article/details/107457353

相关标签: 小程序