1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > [微信小程序]上传单张和多张图片

[微信小程序]上传单张和多张图片

时间:2024-07-30 14:53:47

相关推荐

[微信小程序]上传单张和多张图片

微信小程序开发交流qq群 173683895

承接微信小程序开发。扫码加微信。

上传单张图片并展示,

<button bindtap="upimg" class='jia_img' >上传</button><image src="{{tempFilePaths[0]}}"></image>

data{tempFilePaths:[];},upimg: function () {wx.chooseImage({success: function (res) {var data = {program_id: app.jtappid}var tempFilePaths = res.tempFilePaths //图片wx.uploadFile({url: '', //仅为示例,非真实的接口地址filePath: tempFilePaths[0],name: 'add_image', //文件对应的参数名字(key)formData: data, //其它的表单信息success: function (res) {}})}})},

上传多张图片并展示:

<view class="big-logos"><image bindtap="upimg" src='../../../image/s.png'></image><block wx:for="{{img_arr}}" wx:key="index"><view class='logoinfo'><text class='xxx' bindtap='xxx' data-index='{{index}}'>x</text><image src='{{item}}'></image></view></block></view><button class='top_20 btn' bindtap="upconfirm">确定</button>

upconfirm: function () {this.up();},up: function () {var that = this;data = {openid: app.openid,program_id: app.program_id,only_num: only_num}wx.uploadFile({url: 'pg.php/Aishen/upload_photo',filePath: that.data.img_arr[i],name: 'image', //文件对应的参数名字(key)formData: data, //其它的表单信息success: function (res) {}, complete: function (complete) {console.log(complete)i++if (i == that.data.img_arr.length) {util.request('/pg.php/Aishen/uploade_photo_r', 'post', { 'only_num': only_num }, '正在加载数据', function (res) {console.log(res)if (res.data.state == 1) {wx.showModal({title: '提示',content: '提交成功!',success: function (res) {that.onLoad()wx.navigateBack({delta: 1})}})} else {wx.showModal({title: '提示',content: '提交失败,请重新提交!',})}})} else if (i < that.data.img_arr.length) {//若图片还没有传完,则继续调用函数that.up()}}})},

// 上传upimg: function () {var that = this;if (this.data.img_arr.length < 12) {wx.chooseImage({sizeType: ['original', 'compressed'],success: function (res) {that.setData({img_arr: that.data.img_arr.concat(res.tempFilePaths)})num = that.data.img_arr.length}})} else {wx.showToast({title: '最多上传12张图片',icon: 'loading',duration: 3000});}},

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