微信小程序-用户信息添加到云端
一、效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/61639b29a345c6e83b78f894650a51eb.gif)
二、实现
1.wxml
2.js
var that;
const db = wx.cloud.database();
Page({
data: {
userInfo:null,
},
bindGetUserInfo(e){
console.log(e);
if(e.detail.userInfo){
wx.setStorage({
data: JSON.stringify(e.detail.userInfo),
key: 'userInfo',
success(res){
console.log("setStorage success:",res);
that.addUser(e.detail.userInfo);
}
})
}
else{
}
},
addUser(userInfo){
db.collection('user').add({
data:{
nickName:userInfo.nickName,
avatarUrl:userInfo.avatarUrl,
gender:userInfo.gender,
city:userInfo.city,
province:userInfo.province,
time:new Date()
}
})
.then(res=>{
console.log("add user success",res);
})
.catch(err=>{
console.error("add user fail",err);
})
},
onLoad: function (options) {
that = this;
},
})