标签:image path ack 处理 back info 小程序开发 over set
1.微信小程序API之图片选择与调用微信拍照
wx.chooseImage选择图片(以下为主体代码)
 <view bindtap="bindViewTap" class="userinfo">
    <image class="userinfo-avatar" src="{{avatarUrl}}" background-size="cover"></image>
    <text class="userinfo-nickname">{{userInfo.nickName}}</text>
  </view>
data: {
    motto: ‘Hello World‘,
    userInfo: {},
    avatarUrl:‘/image/logo.png‘
  },
  //事件处理函数
  bindViewTap: function() {
    var that=this;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: [‘original‘, ‘compressed‘], // 可以指定是原图还是压缩图,默认二者都有
      sourceType: [‘album‘, ‘camera‘], // 可以指定来源是相册还是相机,默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths;
        console.log(tempFilePaths);
        that.setData({avatarUrl:tempFilePaths[0]});
      }
    })
  },
标签:image path ack 处理 back info 小程序开发 over set
原文地址:http://www.cnblogs.com/zhihou/p/7805308.html