zoukankan      html  css  js  c++  java
  • <router-link>属性详解

    <router-link>组件支持用户在具有路由功能的应用中点击导航。通过to属性指定目标地址,默认渲染为带有正确连接的 <a> 标签,可以通过配置tag属性生成别的标签。另外,当目标路由成功激活时,链接元素自动设置一个表示激活的css类名

    <router-link>组件的属性有:

    to 、replace、 append、 tag、 active-class、 exact 、 event、 exact-active-class

    to(必选参数):类型string/location

    表示目标路由的链接,该值可以是一个字符串,也可以是动态绑定的描述目标位置的对象

    <!-- 字符串 -->
    <router-link to="home">Home</router-link>
    <!-- 渲染结果 -->
    <a href="home">Home</a>
     
    <!-- 使用 v-bind 的 JS 表达式 -->
    <router-link v-bind:to="'home'">Home</router-link>
     
    <!-- 不写 v-bind 也可以,就像绑定别的属性一样 -->
    <router-link :to="'home'">Home</router-link>
     
    <!-- 同上 -->
    <router-link :to="{ path: 'home' }">Home</router-link>
     
    <!-- 命名的路由 -->
    <router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link>
     
    <!-- 带查询参数,下面的结果为 /register?plan=private -->
    <router-link :to="{ path: 'register', query: { plan: 'private' }}">Register</router-link>

    replace

    • 类型: boolean
    • 默认值: false

    设置 replace 属性的话,当点击时,会调用 router.replace() 而不是 router.push(),于是导航后不会留下 history 记录。

    <router-link :to="{ path: '/abc'}" replace></router-link>

     append

    • 类型: boolean
    • 默认值: false

    设置 append 属性后,则在当前(相对)路径前添加基路径。例如,我们从 /a 导航到一个相对路径 b,如果没有配置 append,则路径为 /b,如果配了,则为 /a/b

    tag

    • 类型: string
    • 默认值: “a”

    有时候想要 <router-link> 渲染成某种标签,例如 <li>。 于是我们使用 tag prop 类指定何种标签,同样它还是会监听点击,触发导航。

    <router-link to="/foo" tag="li">foo</router-link>
    <!-- 渲染结果 -->
    <li>foo</li>

      

    active-class

    • 类型: string
    • 默认值: “router-link-active”

    设置 链接激活时使用的 CSS 类名。默认值可以通过路由的构造选项 linkActiveClass 来全局配置。

    <router-link :to="{path:'/about'}" active-class="activeClass">about</router-link>

    默认值通过路由的构造选项 linkActiveClass 来全局配置,如下示例:

    export default new Router({
      mode:'history',
      linkActiveClass:'is-active',
      routes: [
        {
          path:'/about',
          component:about
        }
    ]
    })

     exact

    • 类型: boolean
    • 默认值: false

    “是否激活” 默认类名的依据是 inclusive match (全包含匹配)。 举个例子,如果当前的路径是 /a 开头的,那么<router-link to="/a">也会被设置 CSS 类名。

    按照这个规则,<router-link to="/"> 将会点亮各个路由!想要链接使用 “exact 匹配模式”,则使用 exact 属性:

    <!-- 这个链接只会在地址为 / 的时候被激活 -->
    <router-link to="/" exact>
  • 相关阅读:
    POJ 1401 Factorial
    POJ 2407 Relatives(欧拉函数)
    POJ 1730 Perfect Pth Powers(唯一分解定理)
    POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)
    POJ 2551 Ones
    POJ 1163 The Triangle
    POJ 3356 AGTC
    POJ 2192 Zipper
    POJ 1080 Human Gene Functions
    POJ 1159 Palindrome(最长公共子序列)
  • 原文地址:https://www.cnblogs.com/hellocd/p/13560147.html
Copyright © 2011-2022 走看看