1.wxml页面
<button open-type="chooseAvatar" bindchooseavatar="getAvatar">
</button>
2.js
拿临时地址上传到后台
getAvatar(e) {
console.log(e)
var that = this
wx.uploadFile({
url: '上传地址',
filePath: e.detail.avatarUrl,
name: "avatarfile",
formData: {
'user': 'test'
},
header: {
"Content-Type": "multipart/form-data"
},
method: 'post',
success: function (res) {
console.log(res)
wx.showToast({
title: "上传成功",
icon: "none",
duration: 1500
})
that.setData({
avatarUrl: res.data
})
},
fail: function (err) {
wx.showToast({
title: "上传失败",
icon: "none",
duration: 2000
})
},
complete: function (result) {}
})
},
3.如果没有弹窗,调整一下版本