思路:
1 、先判断缓存中有没有token
2 、没有 跳转到登陆页面 进行获取token
3 、有token跳转到首页
上代码
wxml:
<button type="primary" plain open-type="getUserInfo" bindgetuserinfo="handleGetUserInfo" > 登录 </button>
js:
Page({ handleGetUserInfo(e){ // 1 判断缓存中有没有token const token = wx.getStorageSync("token"); // 2 判断 if (!token) { // 3 存入缓存 wx.setStorageSync("token", token); const {userInfo}=e.detail; wx.switchTab({ url: '/pages/auth/index' }); return; } } })