小程序开发提升

走远了吗. 提交于 2020-01-16 04:31:39

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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!