微信小程序> 小程序图片上传

小程序图片上传

浏览量:796 时间: 来源:骑着蜗牛一路狂奔

// 调用摄像头

 button class='photo_left_text' bindtap='addphoto'添加照片/button
data:{ album: ["album","camera"],//相册或者摄像头}//选择照片  addphoto(e){    let that = this;    wx.showActionSheet({//选择相册或者拍照api      itemList: ['相册选择', '拍照'],      success: (res) = {        if (res.tapIndex == 0) {          // 相册          wx.showLoading({            title: '上传中',          });          wx.chooseImage({//获取图片            count: "1",//获取图片数量最多能从相册获取9张            sizeType: ["original"],            sourceType: [that.data.album[res.tapIndex]],            success: function (res) {              that.phonts(res.tempFilePaths[0]);            },          })        } else {          // 相机          wx.showLoading({            title: '上传中',          });          wx.chooseImage({            count: "1",            sizeType: ["original"],            sourceType: [that.data.album[res.tapIndex]],            success: function (res) {              that.phonts(res.tempFilePaths[0]);            },          })        }      }    })  },  //调用后台接口把图片上传到后台并返回路径  phonts(t){    let that=this;    wx.uploadFile({      url: 'https://test.com',//后台接口      filePath: t,      name: 'file',//后台接口的名字      success(r) {        console.log('成功', r)        wx.hideLoading();        that.setData({          photo: r.data        });      },      fail(e) {        console.log("失败", e)      }    })  },

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎