微信小程序(登录篇)

思路:

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

 

posted @ 2020-12-27 22:25  会飞的小白  阅读(124)  评论(0编辑  收藏  举报