WML:
<button catchtap=“selectAvatar”>选择头像</button>
JS:
selectAvatar: function(e){
var that = this
wx.chooseImage({
count: 1, // 最多可以选择的图片张数,默认9
sizeType: [‘original’, ‘compressed’], // original 原图,compressed 压缩图,默认二者都有
sourceType: [‘album’, ‘camera’], // album 从相册选图,camera 使用相机,默认二者都有
success: function(res){
if(res.tempFilePaths.length > 0)
{
that.data.newAvatar = res.tempFilePaths[0]
}
},
fail: function() {
// fail
},
complete: function() {
// complete
}
})
var path = that.data.newAvatar
that.setData({newAvatar: path})
console.log(that.data.newAvatar)
}
})
如上,在调用wx.chooseImage后,接口卡死,卡死表现是上面加粗的代码没有执行,待第二次出发上面的selectAvatar时,才会上面加粗的代码