小程序开发提升

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]});
}
})
},

日常所遇,随手而记。
原文地址:https://www.cnblogs.com/zhihou/p/7805308.html