zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Mysql基础
    Mysql基础2
    Windows CMD命令大全
    python 调试方法
    LDAP
    Linux 内核与模块调试
    Linux tee命令
    Linux kgdb命令
    OpenSSL基础知识
    Linux top命令
  • 原文地址:https://www.cnblogs.com/huangmin1992/p/8528617.html
Copyright © 2011-2022 走看看