1、uni.login实现登录功能
// 保存
onSubmit() {
// 这里做一次赋值是为了解决this点不到data中的数据
var that = this
// 登录
uni.login({
provider: 'weixin', //使用微信登录
onlyAuthorize: true, // 微信登录仅请求授权认证
success: function(e) {
console.log(e);
const {code} = e
console.log(that.userName, that.avatarUrl)
// 判断头像以及昵称不为空 再上传
if (that.userName && that.avatarUrl) {
getLoging(
that.userName, that.avatarUrl
).then(res => {
console.log('res', res)
})
console.log("登录成功")
uni.switchTab({
url: '/pages/mainfist/mainfist'
});
} else {
uni.showToast({
icon: 'none',
title: '请上传头像并填写昵称'
})
return false;
}
},
fail: function(err) {
console.log('err', err);
}
})
}