uniapp判断有没有登陆
时间: 2023-11-08 12:54:31 浏览: 195
vue 判断用户是否登陆
在uni-app中,可以使用token来判断用户是否已经登录。在App.vue文件的onLaunch生命周期中,可以使用uni.getStorageSync('token')方法获取token的值。如果token存在,则关闭启动页并跳转到首页。如果token不存在,则关闭启动页并跳转到登录页。具体代码如下所示:
```javascript
onLaunch: function() {
console.log('App Launch');
// #ifdef APP-PLUS
// 使用token标志来判断是否已登录
let token = uni.getStorageSync('token');
if (token) {
// 已登录,则关闭启动页并跳转至首页
plus.navigator.closeSplashscreen();
} else {
// 未登录,则跳转至登录页
uni.reLaunch({
url: "/pages/login/login",
success: () => {
plus.navigator.closeSplashscreen();
}
})
}
// #endif
}
```
你可以参考uni-app文档中的相关内容来了解更多信息,文档地址为:https://uniapp.dcloud.io/collocation/manifest?id=splashscreen [3<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [uniapp 判断用户登录过,直接进入首页](https://blog.csdn.net/weixin_68166404/article/details/131487111)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [uniapp 判断是否登录,是跳转至首页,否跳转至登录页](https://blog.csdn.net/weixin_43887780/article/details/114638694)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文