发布图片,上传图片个数

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

AI助手支持GPT4.0

发布图片,上传图片个数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-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
为什么我的视频号都认证了,但还是只有IOS上面才看得到入口,android机上面依然没有视频号入口?
把背景图片放到服务器上,请求地址是https的背景图片不显示?
wx.chooseMessageFile为什么拉不起本地文件目录?
刚购买的备案的域名,微信无法打开,请问如何解决
开发了商城的小程序,微信官方能给开网络经营证明吗?
随便看看
微信公众号免300认证教程 5100
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 4413
小程序广告组件通过审核,但是小程序内没有显示广告? 4385
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8412
问题? 7629
如何快速搭建抽奖助手小程序(无需代码知识) 5200
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6465
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5770
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5430
如何解决渲染层网络错误Failed to load media? 16679