zoukankan      html  css  js  c++  java
  • 微信小程序下载图片到本地

    downloadImg: function(e){                //触发函数
        console.log(e.currentTarget.dataset.url)
        wx.downloadFile({
          url: e.currentTarget.dataset.url,       //需要下载的图片url
          success: function (res) {            //成功后的回调函数
            wx.saveImageToPhotosAlbum({         //保存到本地
              filePath: res.tempFilePath,
              success(res) {
                wx.showToast({
                  title: '保存成功',
                  icon: 'success',
                  duration: 2000
                })
              },
              fail: function (err) {
                if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
                  wx.openSetting({
                    success(settingdata) {
                      console.log(settingdata)
                      if (settingdata.authSetting['scope.writePhotosAlbum']) {
                        console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
                      } else {
                        console.log('获取权限失败,给出不给权限就无法正常使用的提示')
                      }
                    }
                  })
                }
              }
            })
          }
        });
      },
  • 相关阅读:
    法正(44):鄙视
    法正(43):许攸
    法正(42):孔明
    法正(41):帮派
    法正(40):常委
    法正(39):寡妇
    法正(38):吴苋
    法正(37):刘备
    法正(29):暗弱
    法正(36):花瓶
  • 原文地址:https://www.cnblogs.com/lhj-blog/p/11046399.html
Copyright © 2011-2022 走看看