微信小程序 for循环保存照片

Page({

    data: {

        imgI:0

    }

})


loadImg(){

        let that=this,image=that.data.listimg,i=that.data.imgI;

        for(i;i<image.length;i++){

            wx.downloadFile({

                url: that.data.url+image[i],

                success (res) {

                    if (res.statusCode === 200) {

                        wx.saveImageToPhotosAlbum({

                            filePath: res.tempFilePath,

                            success(res){

                                if (i==image.length) {

                                    wx.showToast({

                                        title: '保存成功',

                                    })

                                } else {

                                    that.setData({

                                        imgI:i+1

                                    })

                                    that.loadImg()

                                }

                            }

                        })

                    }

                }

            })

        }


    },

推荐阅读更多精彩内容