• 4. 3 配置Mysql与注册登录模块(下)


    学习目标

    1. 前端页面授权
    2. 注册页面
    3. 登录状态的持久化

    学习内容

    实现前端页面的授权

    import { createRouter, createWebHistory } from 'vue-router'
    import PkIndexView from '../views/pk/PkIndexView'
    import RecordIndexView from '../views/record/RecordIndexView'
    import UserBotIndexView from '../views/user/bot/UserBotIndexView'
    import NotFound from '../views/error/NotFound'
    import RankListindexView from '../views/ranklist/RankListIndexView'
    import UserAccountLoginView from '../views/user/account/UserAccountLoginView'
    import UserAccountRegisterView from '../views/user/account/UserAccountRegisterView'
    import store from '../store/index'
    
    
    const routes = [
      // 当之输入网址localhost:8080时,跳转重定向
    
      {
        path: "/",
        name: "home",
        redirect: "/pk/",
        meta: {
          requestAuth: true,
        }
      },
      {
        path: "/pk/",
        name: "pk_index",
        component: PkIndexView,
        // 对某个页面进行授权
        meta: {
          requestAuth: true,
        }
      },
      {
        path: "/record/",
        name: "record_index",
        component: RecordIndexView,
    
        meta: {
          requestAuth: true,
        }
      },
      {
        path: "/ranklist",
        name: "ranklist_index",
        component: RankListindexView,
    
        meta: {
          requestAuth: true,
        }
      },
      {
        path: "/user/bot/",
        name: "user_bot_index",
        component: UserBotIndexView,
    
        meta: {
          requestAuth: true,
        }
      },
      {
        path: "/user/account/login/",
        name: "user_account_login",
        component: UserAccountLoginView,
        meta: {
          requestAuth: false,
        }
      },
      {
        path: "/user/account/register/",
        name: "user_account_register",
        component: UserAccountRegisterView,
    
        meta: {
          requestAuth: false,
        }
      },
      {
        path: "/404/",
        name: "404",
        component: NotFound,
        meta: {
          requestAuth: false,
        }
      },
      // 当输入乱七八糟的额网址时,跳转404
      {
        path: "/:catchAll(.*)",
        redirect: "/404/"
    
      }
    ]
    
    const router = createRouter({
      history: createWebHistory(),
      routes
    })
    
    
    //  router再执行之前,先调用这个函数
    router.beforeEach((to, from, next) => {
      if (to.meta.requestAuth && !store.state.user.is_login) {
        next({ name: "user_account_login" })
      } else {
        next();
      }
    })
    export default router
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107

    登录持久化:
    就是将token存储到浏览器的本地硬盘里面localstory.

    注册效果完成

    在这里插入图片描述

  • 相关阅读:
    CSS 属性学习笔记(入门)
    STM32-无人机-电机-定时器基础知识与PWM输出原理
    12.Gateway新一代网关
    【PyCharm】安装第三方库
    Java中的Iterator
    渗透测试之信息收集思路(分析网站架构)
    Linux命令之shred命令
    off-by-one+overlapped chunk
    基于SpringCloud和Vue的前后端分离-预约挂号系统
    网络编程、socket编程、多进程并发服务器
  • 原文地址:https://blog.csdn.net/qq_36288669/article/details/126153635