小程序实现保存网络图片到本地


**这里贴上关于小程序实现保存网络图片到本地的代码,可直接复制到项目中**

<script>

      wx.getSetting({
      
        success(res) {
      
          wx.downloadFile({
      
            url:
              "http://mss.sankuai.com/v1/mss_51a7233366a4427fa6132a6ce72dbe54/newsPicture/05558951-de60-49fb-b674-dd906c8897a6",
            success: function(res) {
      
              console.log(res);
              wx.saveImageToPhotosAlbum({
      
                filePath: res.tempFilePath,
                success: function(data) {
      
                  wx.showToast({
      
                    title: "保存成功",
                    icon: "success",
                    duration: 2000
                  });
                },
                fail: function(err) {
      
                  console.log(err);
                },
                complete(res) {
      
                  console.log(res);
                }
              });
            }
          });
        }
      });
      script>
      

你可能感兴趣的:(mpvue小程序,保存图片,小程序,到本地)