promise和callback两种不同的方式
// promise方式
// uniCloud.uploadFile({
// cloudPath: Date.parse(new Date()) + '/' + Math.floor(Math.random() * 100) + 1 + ".jpg",
// filePath: this.avatar,
// }).then(res => {
// if (res.fileID) {
// this.$reqs.updateUser({
// userInfo: {
// nickName: this.userName,
// avatarUrl: res.fileID
// },
// }).then(res => {
// console.log(res)
// })
// }
// })
// callback方式
uniCloud.uploadFile({
cloudPath: Date.parse(new Date()) + '/' + Math.floor(Math.random() * 100) + 1 + this.avatar.substring(this.avatar.length-4),
filePath: this.avatar,
success: res => {
this.avatar = res.fileID
if(res.fileID){
this.$reqs.updateUser({userInfo:{nickName:this.userName,avatarUrl:this.avatar},}).then(res=>{
console.log(res)
})
}
},
fail: err => {
console.log(err)
}
})