zoukankan      html  css  js  c++  java
  • vue-router基础使用

    router.js文件

    import Vue from 'vue'
    import Router from 'vue-router'
    import Home from './views/Home.vue'
    // import List from './views/List.vue'
    import Detail from './views/Detail.vue'
    
    Vue.use(Router)
    
    const router =  new Router({
      mode: 'history',
      base: process.env.BASE_URL,
      routes: [
        {
          path: '/',
          component: Home,
          children: [{
            path: '/list',
            name: 'list',
            component: () => import('./views/List.vue')
          },
          {
            path: '/detail/:id',
            component: Detail,
            props: true
          }]
        },
        {
          path: '/about',
          name: 'about',
          meta: {auth: true}, // 需要认证---路由守卫
          // beforeEnter(){}, // 路由级钩子
          component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
        }
      ]
    })
    
    // 全局守卫,路由的全局钩子
    router.beforeEach((to, from, next) => {
      if(to.meta.auth && !window.isLogin){
        if(window.confirm('请登录')){
          window.isLogin = true
          next() // 登录成功,继续下一步
        }else{
          next('/') // 放弃会首页
        }
      }else {
        next() // 不需要登录,继续
      }
    })
    
    export default router

    About.vue中

    <template>
      <div class="about">
        <h1>This is an about page</h1>
      </div>
    </template>
    <script>
    export default {
      // beforeRouteEnter(){} // 组件级钩子
    }
    </script>
  • 相关阅读:
    centos6安装部署ntp
    pttablechecksum和pttablesync修复主从不一致的数据
    clickhouse数据导入导出
    mongodb执行js结果输出文件
    rman验证备份有效性
    使用expdp和impdp进行goldengate初始化
    安装goldengate软件(ogg)
    sql ltrim rtrim
    2022
    Mqtt服务部署
  • 原文地址:https://www.cnblogs.com/haishen/p/11308674.html
Copyright © 2011-2022 走看看