【微信小程序】從雲端獲取圖片下載,轉入本地圖片臨時路徑

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章