uni-app 登錄/注銷后頁面刷新


1.模板

<template>

<view class="flex flex-direction">
<button class="cu-btn bg-red lg" @click="LoginByUUID">一鍵登錄</button>
</view>

</template>

2.方法的實現

<script>

//獲取默認用戶
LoginByUUID() {
var that = this;
var params = {
uuid: "12165486543165455",
nickname: "mjq"
}
this.$api.LoginByUUID(params).then(res => {
console.log(res)
if (res.success && res.code == 200) {
that.userInfo = res.result.userInfo;
console.log(that.userInfo);
uni.setStorageSync("userInfo.uuid",params.uuid)
uni.setStorageSync("userInfo.nickname",params.nickname)
uni.setStorageSync("userInfo",that.userInfo)
}
uni.navigateBack({
delta:3
})
uni.showToast({
title:"登錄成功",
icon:'none'
})
})
}

</script>

3.實現頁面刷新,在onShow中重新獲取一次數據

onShow(options) {

this.getVideos();
this.userInfo = uni.getStorageSync("userInfo");
console.log(this.userInfo)
},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM