uniapp getUserProfile の使い方
uni.getUserProfile を使用する理由
使用 uniapp 开发微信小程序时之前用的是 uni.getUserInfo,现在由于微信方面接口调整
(https://developers.weixin.qq.com/community/develop/doc/000cacfa20ce88df04cb468bc52801)
现已改为 getUserProfile; 原来的 getUserInfo 接口可获取用户个人信息能力被回收, 还能返回数据但很
多关键数据是空的, 提示授权的弹窗更是没有。所以要使用新的 getUserProfile 接口。
uni.getUserProfile 使用例
<template>
<view class="login-container">
<button class="btn-login" type="primary" @click="getUserInfo">一键登录</button>
</view>
</template>
<script>
export default {
name: 'my-login',
methods: {
getUserInfo(e) {
uni.getUserProfile({
lang: 'zh_CN',
desc: '用来授权登录该小程序!',
success: (userInfo) => {
uni.$showMsg('登录成功!')
},
fail: () => {
uni.$showMsg('登录失败!')
},
complete: () => {
},
})
},
},
}
</script>
具体的な手順
- ボタンにクリック イベントをバインドできます。
- クリック イベント ハンドラで uni.getUserProfile を呼び出します。
- 必要なプロパティを構成オブジェクトに追加します
参照文書
- WeChat ミニ プログラムの公式ドキュメント
- ユニアプリの公式ドキュメント