zoukankan      html  css  js  c++  java
  • vue-router封装

    用户是否需要登录

    import Vue from 'vue'
    import Router from 'vue-router'

    Vue.use(Router)
    const routes = [{
      path: '/',
      redirect: '/home'
      },
      {
        path: '/home',
        name: 'home',
        component: () =>import('./views/Home.vue'),
        meta: {
          requireAuth: true, // 添加该字段,表示进入这个路由是需要登录的
        },
        children: [{
          path: '/account_management',
          name: 'account_management',
          component: () =>import('./views/admin/account_management.vue')
        }]

      },
      {
        path: '/login',
        name: 'login',
        component: () =>
        import('./views/login/login.vue')
      }

    ]
    const router = new Router({
      routes
    })
    //路由拦截器
    router.beforeEach((to, from, next) => {
      //根据字段判断是否路由过滤
      if(to.meta.requireAuth) { // 判断该路由是否需要登录权限
        if(localStorage.getItem('sid')) { //身份信息获取
          next();
        } else {
          next({
            path: '/login'
          })
        }
      } else {
        next();
      }
    });
    export default router;

  • 相关阅读:
    poj 3258
    CodeForces 367E Sereja and Intervals
    Codeforces Round #240 (Div. 2) C Mashmokh and Numbers
    Codeforces Round #240 (Div. 2) D
    zoj 3768 Continuous Login
    2014/4/4做题感悟
    HDU 1878 欧拉回路
    HDU 3018 Ant Trip
    POJ 3694 Network
    Codeforces Round #239 (Div. 2)
  • 原文地址:https://www.cnblogs.com/92xcd/p/9933457.html
Copyright © 2011-2022 走看看