Pictures of small micro-channel program to upload problem

Our company uses mpvue develop small program, I encountered when doing product reviews this one picture to upload some problems, because the picture is one upload applet, so I use a for loop to loop multiple images to upload, I with the two arrays, an array put the picture now displayed in the address for the page, a data release is to return after upload pictures to the server address of the picture, for delivery to the back end, but I find that not cycle once again perform the upload operation, but for the first implementation cycle is almost finished, began to perform the upload operation, which led to the order and the server returns an array of pictures is not the same as when I removed the address of a location in the array and then upload this picture, the server is returned according to the position of my previous data, such as deleting the third, but the third address returned by the server may be the second return, then you upload, server, or you return to the second, it led to a repeat picture, a word that can not be recycled uploaded by for, with that What does? Recursive, attach the code

// 上传图片
    clickChooseImg() {
      let that = this;
      const s = 0;
      wx.chooseImage({
        count: 4,
        sizeType: ["original", "compressed"],
        sourceType: ["camera",'album'],
        success: function(res) {
          let tempFilePaths = res.tempFilePaths;
          if (tempFilePaths.length != 0) {
            for (let s = 0; s < tempFilePaths.length; s++) {
              that.imageList.push(tempFilePaths[s]);
            };
            that.reqUpload(tempFilePaths, s , tempFilePaths.length);
          }
        }
      })
    },
    // 上传图片至七牛
    reqUpload(tempFilePaths, s , len) {
      let that = this
      wx.uploadFile({
        url: "xxxxxxxxxxxxxxxxxxxxxxx",
        filePath: tempFilePaths[s],
        name: "file",
        formData: {
          token: that.token
        },
        success: function(res) {
          that.onlineImageList.push(that.addressPrefix + JSON.parse(res.data).key);
        },
        complete: function(){
          s++;
          if(s < len){
            that.reqUpload(tempFilePaths,s,len);
          }
        }
      })
    },

 

Guess you like

Origin www.cnblogs.com/zmhl/p/11413439.html