【微信小程序】从云端获取图片下载,转入本地图片临时路径

xinxin1: function (imgs) {

    var that = this;
    var contex = that.data.dataList1;
    console.log("contex:",contex)
    //var arr = data.list;
    var arr=[];
    for (var i = 0, len = contex.length; i < len; i++) {
      var imgs = {};
      imgs = contex[i].imgUrl;
      console.log(contex[i].imgUrl);//遍历输出
      arr.push(imgs)
      console.log("内部imgs", imgs)
    } ;
    console.log("外部arr", arr)
    var random = Math.floor(Math.random() * 10);
    imgs = arr[random],
      console.log("最后打印", imgs)

    that.setData({
      dataimg1: imgs
    })

    wx.cloud.downloadFile({
      fileID: imgs, // 文件 ID
      maxAge: 120 * 60 * 1000,
      success: res => {
        // 返回临时文件路径
        console.log("临时文件",res.tempFilePath)
        that.setData({
          graph: {
            w: 200,
            h: 200,
            type: 'image',
            url: res.tempFilePath,
          }
        });
      
      },
      fail: console.error
    })

 

你可能感兴趣的:(微信小程序)