路由设置,判断是否存在对应的cookie
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
router.get("/checkLogin", function (req,res,next) { if(req.cookies.userId){ res.json({ status:'0', msg:'', result:req.cookies.userName || '' }); }else{ res.json({ status:'1', msg:'未登录', result:'' }); } }); |
VUE中mounted checkLogin()
1 2 3 4 5 6 |
mounted(){ this.checkLogin(); }, methods:{ checkLogin(){ axios.get("/users/checkLogin").then((response)=>{ |
未经允许不得转载:MR LYU » checkLogin()