這裏主要用到button的open-type功能,官網已有説明:
給button設置open-type="chooseAvatar",來使bindchooseavatar方法生效,在bindchooseavatar指定的函數中獲取用户的頭像信息
<button open-type="chooseAvatar" bindchooseavatar="chooseavatar"></button>
chooseavatar(e){
this.setData({
avatar: e.detail.avatarUrl
})
},
該方法觸發後會自動彈出提示框,讓用户選擇頭像,用户選擇的頭像會在bindchooseavatar指定的函數內獲取,e.detail.avatarUrl就是當前的頭像信息。
調用修改用户信息接口,傳入該路徑信息即可。