日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

uniapp获取用户登录信息的实现

發布時間:2024/5/14 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uniapp获取用户登录信息的实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用戶登錄需要拿到以下參數,因為getUserInfo已經不再有彈出層了,使用我們改用getUserProfile獲取數據

1.點擊登錄按鈕獲取微信用戶的基本信息:

<button type="default" v-on:click="dianji()">一鍵登錄</button>

2.在methods節點中聲明getUserInfo事件處理函數

methods:{dianji(){uni.getUserProfile({desc: '用于完善用戶資料', success(e) {console.log(e.userInfo);},fail() {uni.showToast({icon:null,title:'您取消了登錄授權'})}})}}

3.獲取code參數:

const [err,res] = await uni.login().catch(err=>err); if(res.errMsg !== 'login:ok'){return uni.showToast({title:'登錄失敗!'}) } console.log(res.code);

4.把5個參數放在data的一個對象當中

data() {return {query:{code:'',encryptedData:'',iv:'',signature:''},userInfo:{}}; }, methods:{dianji(){var that = this;uni.getUserProfile({desc: '用于完善用戶資料', success(e) {//保存參數信息that.get();that.query.encryptedData = e.encryptedData;that.query.iv = e.iv;that.query.signature = e.signature;that.query.rawData = e.rawData;//保存用戶信息that.userInfo = e.userInfo;},fail() {uni.showToast({icon:null,title:'您取消了登錄授權'})},});},async get(){const [err,res] = await uni.login().catch(err=>err);if(err || res.errMsg !== 'login:ok'){return uni.showToast({title:'登錄失敗!'})}console.log(res.code);this.query.code = res.code;}}

5個參數已經全部保存在data下的query對象當中

5.將code傳給后臺處理:

methods:{ dianji(){var that = this;uni.getUserProfile({desc: '用于完善用戶資料', success(e) {//保存參數信息that.get().then(res=>{that.query.encryptedData = e.encryptedData;that.query.iv = e.iv;that.query.signature = e.signature;that.query.rawData = e.rawData;//保存用戶信息that.userInfo = e.userInfo;console.log('發送請求');uni.request({url:'http://localhost:3000/test?code='+that.query.code,method:'GET',success(res) {console.log(res);}})})},fail() {uni.showToast({icon:null,title:'您取消了登錄授權'})},});}, async get(){const [err,res] = await uni.login().catch(err=>err);if(err || res.errMsg !== 'login:ok'){return uni.showToast({title:'登錄失敗!'})}this.query.code = res.code;console.log('code'+this.query.code); } }

總結

以上是生活随笔為你收集整理的uniapp获取用户登录信息的实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。