Wechat applet local image upload

Today, I made a local image upload function, you can choose a single image or multiple images, and organize them every day.




code up

wxml:

<button type="primary" bindtap='image'>选择图片</button>
<view wx:for='{{imgArray}}'>
  <image src='{{item}}'></image>
</view>



js:

data: {
    imgArray: []
  },
  image:function(e){
    var _this = this;
    wx.chooseImage({
      count: 9, // default 9
      sizeType: ['original', 'compressed'], // You can specify the original image or the compressed image, both by default
      sourceType: ['album', 'camera'], // You can specify whether the source is an album or a camera, both by default
      success: function (res) {
        console.log(res);
        // Returns a list of local file paths for the selected photo, tempFilePath can be used as the src attribute of the img tag to display the image
        _this.setData({
          imgArray: res.tempFilePaths
        })
      }
    })
  },

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325693272&siteId=291194637