1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 微信小程序上传图片(限制图片大小 张数)

微信小程序上传图片(限制图片大小 张数)

时间:2022-06-30 01:31:35

相关推荐

微信小程序上传图片(限制图片大小 张数)

代码:

//选择图片choice: function () {var that = thisconsole.log(that.data.imgsrc.length);if (that.data.imgsrc.length <= 3) {var ino = 4 - that.data.imgsrc.length;wx.chooseImage({//从本地相册选择图片或使用相机拍照count: ino,sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: (res) => {var tempFilePaths = res.tempFilePathsfor (var item in res.tempFilePaths) {console.log(res.tempFilePaths[item]);that.data.imgsrc.push(res.tempFilePaths[item]);tempFilePaths = that.data.imgsrc;console.log(that.data.imgsrc);}let size = tempFilePaths.every(item => {//限制上传图片大小为2M,所有图片少于2M才能上传return item.size <= 2000000})if (size) {that.setData({imgsrc: tempFilePaths})}else{wx.showToast({title:'上传图片不能大于2M!',icon:'none' })}}})}else {wx.showToast({title: "最多只能上传4张图片",image: "/images/icon-warning.png",});}},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。