美文网首页
微信小程序 for循环保存照片

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

作者: 安徒生1997 | 来源:发表于2020-12-26 17:04 被阅读0次

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()

                                }

                            }

                        })

                    }

                }

            })

        }

    },

相关文章

网友评论

      本文标题:微信小程序 for循环保存照片

      本文链接:https://www.haomeiwen.com/subject/yvugnktx.html