E企盈营销工具技术服务商 热线:4006-838-530

微信小程序上传图片,微信小程序上传单张或多张图片

E企盈直播平台营销卖货系统

上传作品图片,上传头像(count=1),亲测有效分享一下核心代码,希望能帮助大家1.wxml!–上传作品–viewclass=’upload-works’style=’height:{{screenHeight}}px’wx:if=”{{isUpWork}}”viewclass=’work-box’viewclass=’works-tit’图片上传:/viewviewclass=’works-img’viewwx:for=”{{worksImgs}}”wx:for-item=”item”wx:key=”this”!–图片缩略图–imagesrc=”{{item}}”mode=”aspectFill”/image!–移除图片的按钮–viewdata-index=”{{index}}”catchtap=”deleteImg”删除/view/viewviewclass=’imgiconfonticontianjia’wx:if=”{{worksImgs.length9}}”bindtap=”chooseImage”/view/view/view!–按钮–viewclass=’btns’buttonclass=’cancle’catchtap=’cancleWorks’取消/buttonbuttonclass=’submit’catchtap=’submitWorks’提交/button/view/view2.jschooseImage:function(){letthat=this;letworksImgs=that.data.worksImgs;letlen=that.data.worksImgs.length;wx.chooseImage({count:9-len,//最多选择9张图片sizeType:[‘original’,’compressed’],//可以指定是原图还是压缩图,默认二者都有sourceType:[‘album’,’camera’],//可以指定来源是相册还是相机,默认二者都有success:function(res){console.log(res);//返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片if(res.tempFilePaths.count==0){return;}lettempFilePaths=res.tempFilePaths;//lettoken=app.data.uptoken;//上传图片循环提交for(leti=0;itempFilePaths.length;i++){wx.uploadFile({url:’url’,//此处换上你的接口地址filePath:tempFilePaths[i],name:’upload_file’,header:{“Content-Type”:”multipart/form-data”,’accept’:’application/json’,},success:function(res){console.log(res);letdata=JSON.parse(res.data);//这个很关键worksImgs.push(data.data.url);that.setData({worksImgs:worksImgs})}})}}})},//删除上传的图片deleteImg:function(e){varworksImgs=this.data.worksImgs;varitemIndex=e.currentTarget.dataset.index;worksImgs.splice(itemIndex,1);this.setData({worksImgs:worksImgs})},//提交个人作品submitWorks:function(){letthat=this;letworksImgs=String(that.data.worksImgs);letobj={store_id:that.data.store_id,mode_id:that.data.mode_id,works_img:worksImgs,works_info:that.data.works_info,is_xs:1}if(obj.works_img.length==0||obj.works_info==”){wx.showModal({title:’提示’,content:’数据不能为空!’,showCancel:false,})}else{utils.postRequest(‘Mode/worksAdd’,obj,’加载中’,(res)={if(res.data.rc==200){wx.showModal({title:’提示’,content:’作品上传成功’,showCancel:false,success:function(res){if(res.confirm){that.setData({isUpWork:false})that.onShow();}}})}else{wx.showModal({title:’提示’,content:’作品上传失败’,showCancel:false,success:function(res){if(res.confirm){that.setData({isUpWork:false})that.onShow();}}})}})}},注意:微信公众平台小程序,开发栏目uploadFile合法域名,一定要配置图片保存的域名,例如:七牛云等等

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序上传图片,微信小程序上传单张或多张图片
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏