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

Page({

    data: {

        imgI:0

    }

})


loadImg(){

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

        for(i;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()

                                }

                            }

                        })

                    }

                }

            })

        }


    },

你可能感兴趣的:(微信小程序 for循环保存照片)