zoukankan      html  css  js  c++  java
  • vuerouter-7._路由高亮

    1.router-link-exact-active 精准匹配

    2.router-link-active 匹配

    配置:------------------------------------------------------------------------------------------------------

    import Vue from 'vue'
    import VueRouter from 'vue-router'
    //@表示寻找根目录
    import HelloWorld from '@/components/HelloWorld'
    import learn from '@/components/learn'
    import Basee from '@/components/basee'
    import Http from '@/components/http'
    import NotFound from '@/components/404'
    Vue.use(VueRouter)
    //创建路由
    export default new VueRouter({
    //mode:'history',
    linkActiveClass:"active",
    linkExactActiveClass:"currentactive",
    routes: [{
    path: "/h/:id",
    name: "HelloWorld", //可以作为跳转使用
    component: HelloWorld
    },
    {
    path: "/learn/:id",
    name: "learn",
    component: learn,
    children: [{
    path: "basee",
    component: Basee
    },
    {
    path: "http",
    component: Http
    }
    ]
    },
    {
    path:"/",
    //重定向
    redirect:"/learn"
    },
    {
    path:"*",
    //404
    component:NotFound
    }
    ]
    })

    2.样式-----------------------------------

    <template>
    <div id="app">
    <img src="./assets/logo.png">
    <ul>
    <!-- <router-link to="/h" tag="li">HelloWorld</router-link>
    <router-link to="/learn" tag="li">learn</router-link> -->
    <router-link :to="{name:'HelloWorld',params:{id:helloparams}}" tag="li">HelloWorld</router-link>
    <router-link :to="{name:'learn'}" tag="li">learn</router-link>
    </ul>
    <button class="btn" @click="gotoHello">去learns</button>
    <router-view />
    </div>
    </template>

    <script>
    export default {
    name: 'App',
    components: {

    },
    data(){
    return{
    helloparams:"hellodemo",
    clickParams:"hahaha"
    }
    },
    methods: {
    gotoHello() {
    //this.$router.push("/h")
    //this.$router.replace("/h")
    //this.$router.go(-1)
    this.$router.push({name:"learn",params:{id:this.clickParams}})
    }
    }
    }
    </script>

    <style>
    #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
    }

    ul li {
    text-align: center;
    display: inline-block;
    text-decoration: underline;
    cursor: pointer;
    color: blue;
    }

    ul li+li {
    margin-left: 20px;
    }

    .btn {
    border: 1px solid #fff;
    padding: 5px;
    color: #fff;
    background-color: #0000FF;
    cursor: pointer;
    }

    /* router-link-exact-active 精准匹配
    */
    /* .router-link-active{color:red;} */
    .active{color:red;}
    .currentactive{border:1px solid blue;}
    </style>

  • 相关阅读:
    多角度分析平台即服务?PaaS的类型和用例
    2021.3.10 Android导出Excel表
    2021.3.9 个人作业阶段2
    2021.3.8 Android图像视图1
    2021.3.7 Android图像视图
    2021.3.6 Android页面刷新
    2021.3.5 个人作业1+家庭记账本(8)
    2021.3.4 家庭记账本(7)
    2021.3.3 Android项目打包+家庭记账本(6)
    2021.3.2 开课博客+家庭记账本(5)
  • 原文地址:https://www.cnblogs.com/xiao-peng-ji/p/11337309.html
Copyright © 2011-2022 走看看