开放能力1:
首先给button 添加属性open-type 值选择chooseAvater
绑定bindchooseAvater事件
<view>
<button class="btn" open-type="chooseAvatar" bindchooseavatar="chooseavatar">
<image class="avater" src="{{url}}"></image>
</button>
</view>
在.js文件中:
Page({
data:{
url:"../../assents/头像3.png"
},
chooseavatar(e){
console.log(e)
this.setData({
url:e.detail.avatarUrl
})
}
})
获取头像内容的链接其实是在e.detail.avatarUrl之中,打印看一下:
to be continued ...