小程序如何使用button登录
.wxml文件中的代码
<button style="position:fixed;top:300rpx;" open-type="getUserInfo" bindgetuserinfo="onUserInfoAndGet">
<!-- 自定义样式展示 -->
<cover-view style="backgroud:red;width:100rpx;height:40rpx;"></cover-view>
</button>
.js文件中的代码
onUserInfoAndGet: function(event) {
this.onUserInfo(event);
},
onUserInfo: function (event) {
wx.showLoading({
title: "登录中",
});
wx.login({
success: function(res) {
console.log(res.code);
},
fail: function(error) {
}
});
}