zoukankan      html  css  js  c++  java
  • vue Router路由自我总结

    # npm安装路由、
    # main.js中注入路由
    # router.js中
        import Router from 'vue-router' 
        Vue.use(Router)
    # 定义路由表
    new VueRouter({
        linkActiveClass:'active',  //全局配置 router-link 标签生成的 CSS 类名
        routes:[
            //无嵌套路由
            {
                path:'/'   // '/'表示匹配首页
                name:'****'
                component:*****  
            },
            {
                path:'****'
                name:'****'
                component:*****
            },
            //嵌套路由
            {
                path:'/news'
                name:'****'
                component:*****,
                children:[
                    {
                        path:'/news/sport',   //此写法是绝对路径
                        component:*****
                    },
                    {
                        path:'tech',  //前面没有/,此写法是相对路径,即:/news/tech
                        component:****
                    },
                    {
                        path:'',
                        redirect:'tech'  //重定向到某个路由,即默认选中某个路由
                    }
                ]
            },
        ]
    })
    # 渲染出口
    <router-view></router-view> 
    # 路由跳转 
    <router-link to='/home' tag='li'></router-link> 
    //router-link 默认渲染出来的是 a 标签,如果需要让它渲染出来的是别的标签,则可以使用 tag 属性指定渲染后的标签,例如tag='li'
    //可以在每个 router-link 上使用 active-class 来激活 CSS 类名: active-class='active' ,比较麻烦,需要每个加
      或者在 VueRouter 实例中,使用 linkActiveClass 全局配置 CSS 类名
    //exact 类名精确匹配,用在路由为‘/’的首页上,防止出现切换其他路由时首页样式问题  
    #缓存路由
    <keep-alive>
        <router-view></router-view> 
    </keep-alive>
      被包含在 <keep-alive> 中创建的组件,会多出两个生命周期的钩子: activated 与 deactivated


    #编程式路由
    this.$router.push(path) 相当于点击路由链接(后退1步,会返回当前路由界面)
    this.$router.replace(path) 用新路由替换当前路由(后退1步,不可返回到当前路由界面)
    this.$router.back() 后退回上一个记录路由
    this.$router.go(n) 参数 n 指定步数
    this.$router.go(-1) 后退回上一个记录路由
    this.$router.go(1) 向前进下一个记录路由

    
    
  • 相关阅读:
    [转载]微信企业号开发如何建立连接
    【VB技巧】VB静态调用与动态调用dll详解
    DevExpress 中 汉化包 汉化方法
    DevExpress汉化(WinForm)
    DevExpress 中 WaitForm 使用
    DevExpress 中 DateEdit 控件 格式化显示和编辑的日期格式为: yyyy-MM-dd
    DevExpress 中 用 LookUpEdit 控件 代替 ComboBoxEdit 控件来绑定 DataTable
    asp.net 大文上传配置
    DevExpress中的lookupedit的使用方法详解
    DevExpress控件使用小结
  • 原文地址:https://www.cnblogs.com/mark21/p/13938012.html
Copyright © 2011-2022 走看看