小程序图片下载【实用】

以下内容 直接放入即可 亲测有效

单张下载


下载图片
/* methods */
saveImage() {
          wx.downloadFile({
              url:'http://upload.jianshu.io/admin_banners/web_images/4435/c1d3ca63353c8bd527f0d781605516cb5b266d02.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/1250/h/540',

              success: function(res) {
                  if (res.statusCode === 200) {
                      let img = res.tempFilePath;
                      wx.saveImageToPhotosAlbum({
                          filePath: img,
                          success(res) {
                              console.log('成功')
                          },
                          fail(res) {
                              console.log('保存失败')
                          }
                      });
                  }
              }
          });
      }

多张下载


下载图片
/* methods */
saveImage() {
          let picArr=['http://upload.jianshu.io/admin_banners/web_images/4435/c1d3ca63353c8bd527f0d781605516cb5b266d02.jpg','http://47.102.105.248:8805/img-api/202007/24/1595585519996221273.png']
          this.xiazaiTupian(picArr)
      },
      //下载内容
      xiazaiTupian: function(picArr,index) {
          let that=this;
          index=index||0;
          console.log(picArr[index])
          wx.downloadFile({
              url: picArr[index],
              success: function (res) {
                  var temp = res.tempFilePath
                  console.log(index)
                  console.log(temp)
                  wx.saveImageToPhotosAlbum({
                      filePath: temp,
                      success: function () {
                          index+=1;
                          if (index < picArr.length){
                              that.xiazaiTupian(picArr, index);
                          }else{
                              wx.showToast({
                                  title: '下载完成',
                              })
                          }

                      },
                      fail: function () {
                          index += 1;
                          if (index < picArr.length) {
                              that.xiazaiTupian(picArr, index);
                          } else {
                              wx.showToast({
                                  title: '下载完成',
                              })
                          }
                          wx.showToast({
                              title: '第' + (index+1) + '下载失败',
                          })
                      }
                  })
              },
              fail: function (res) {
                  wx.showToast({
                      title: '下载失败',
                  })
              }
          })

      },

多图下载 -- 小程序(mpvue)内嵌h5






    
    Title
    
    
    
    



    
大师傅但是



你可能感兴趣的:(小程序)