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