uniapp:微信小程序授权登录

1.dom

<view class="ui-wx" @click="getUserProfile"></view>

2.点击授权

getUserProfile(e){
	wx.getUserProfile({
		desc: "获取你的昵称、头像、性别",
		success: res => {
			_this.userInfo = res.userInfo;
			// console.log(this.userInfo,'=====')
			_this.usename = _this.userInfo.nickName
			this.avatarUrl = _this.userInfo.avatarUrl
            // 储存信息
			uni.setStorageSync('usename',_this.usename);
			uni.setStorageSync('avatarUrl',_this.avatarUrl);
			wx.login({
				success:(res) => {
					console.log("res",res)
					console.log(res.code,'登录')
                 },
			})
		},
		fail: res => {
			//拒绝授权
			uni.showToast({
				title:'微信登录授权失败!',
				duration: 2000,
				icon:'none'
			})
			return;
		}
	})		
				
},

猜你喜欢

转载自blog.csdn.net/Ygaidi/article/details/128003858