小程序 上传图片

获取图片

  • wxml

    <!--pages/publish/publish.wxml-->
    <view bindtap="uploadImage">请上传图片</view>
    <view class="container">
      <image wx:for="{{imageList}}" src="{{item}}"></image>
    </view>
    
    
  • js

      data: {
        imageList: ["/static/hg.jpg", "/static/hg.jpg"]
      },
    
      uploadImage:function(){
        var that = this;
    
        wx.chooseImage({
          count:9,
          sizeType: ['original', 'compressed'],
          sourceType: ['album', 'camera'],
          success:function(res){
            // 设置imageList,页面上图片自动修改。
            // that.setData({
            //   imageList: res.tempFilePaths
            // });
    
            // 默认图片 + 选择的图片; 
            that.setData({
              imageList: that.data.imageList.concat(res.tempFilePaths)
            });
          }
        });
      },
    

注意:图片目前只是上传到了内存。

原文地址:https://www.cnblogs.com/angdh/p/14729322.html