wx.chooseImage


<view>上传图片</view>
<view>
    <view>
        <button bindtap="getImg">上传图片</button>
    </view>
    <view wx:for="{{imgSrc}}" wx:key="{{index}}">
        <image mode="aspectFit" src="{{item}}" />
    </view>
</view>
page({
   data:{
        imgSrc:[]     
    },
    getImg(e){
    var _this = this;
    wx.chooseImage({
          count:9,//照片可选数量
          sizeType:['original','compressed'],//原图,缩略图
          sourceType:['album','camera'],//相册,相机
          success:function(res){
                var tempFilePaths = res.tempFilePaths
                console.log(tempFilePaths)
                _this.setData({
                      imgSrc:[..._this.data.imgSrc,...tempFilePaths]
                })
          }
        })
   },     
})    

移动端上传照片时,需要在在wx.upload请求时,添加header:{

"Content-Type": "multipart/form-data"

},

否则,可能传给后天的数据是application/octet-stream


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM