发布图片,上传图片个数

小程序 文章 2021-01-25 14:01 0 10 全屏看文

发布图片,上传图片个数Publish pictures, the number of uploaded pictures

发布图片,上传图片个数

各位前辈大家好,我想请问如何在这段代码中设置上传图片的最少个数,比如最少上传一张图片否则不能发布内容并且做出提示

  chooseImage: function () {    var that = this;    wx.chooseImage({      count9 - that.data.cloudImgList.length,      sizeType: ['original''compressed'],      sourceType: ['album''camera'],      success(res) {        console.log(res.tempFilePaths)        // 上传图片        that.data.tempImgList = res.tempFilePaths        that.uploadImages()      },    })  },  uploadImages() {    var that = this;    for (var i = 0; i < this.data.tempImgList.length; i++) {      wx.cloud.uploadFile({        cloudPath`actionImages/${Math.random()}_${Date.now()}.${this.data.tempImgList[i].match(/.(w+)$/)[1]}`,        filePaththis.data.tempImgList[i],        success(res) {          console.log(res.fileID)          that.data.cloudImgList.push(res.fileID)          that.setData({            cloudImgList: that.data.cloudImgList          })        }      })    }  },

Hello, everyone, I would like to ask how to set the minimum number of uploaded pictures in this code, such as uploading at least one picture, otherwise you can't publish the content and make a prompt "chooseimage: function() {var that = this wx.chooseImage ({      count: 9 -  that.data.cloudImgList .length,      sizeType: ['original',  'compressed'],      sourceType: ['album', 'camera'],      success(res) {         console.log ( res.tempFilePaths )/ / upload pictures that.data.tempImgList  =  res.tempFilePaths          that.uploadImages ()      },    })  },  uploadImages() {    var that = this;     for (var i = 0; i <  this.data.tempImgList .length; i++) {       wx.cloud.uploadFile ({        cloudPath: `actionImages/${ Math.random ()}_ ${ Date.now ()}.${ this.data.tempImgList [i].match(/.(w+)$/)[1]}`,        filePath:  this.data.tempImgList [i],         success(res) {           console.log ( res.fileID )           that.data.cloudImgList .push( res.fileID )           that.setData ({            cloudImgList:  that.data.cloudImgList           })        }      })    }  },

回答:

默认²⁰²⁰:

做判断 当图片数组长度 >=1 在上传 反之弹框即可

brave:

this.data.tempImgList.length >= 1 上传完成后,this.data.tempImgList = []

iW:

不要在选择图片的时候,就上传

1、选择图片,存在一个数组里

2、点击提交按钮,验证数组长度

-EOF-