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)
},