vue、Breadcrumb面包屑、Breadcrumb属性、vue Breadcrumb 全部面包屑、vue Breadcrumb 全部属性

vue、Breadcrumb面包屑、Breadcrumb属性、vue Breadcrumb 全部面包屑、vue Breadcrumb 全部属性

设计规则

显示当前页面在系统层级结构中的位置,并能向上返回。

何时使用

  • 当系统拥有超过两级以上的层级结构时;
  • 当需要告知用户『你在哪里』时;
  • 当需要向上导航的功能时。

代码演示

1.基本

在这里插入图片描述
最简单的用法

<template>
  <a-breadcrumb>
    <a-breadcrumb-item>Home</a-breadcrumb-item>
    <a-breadcrumb-item><a href="">Application Center</a></a-breadcrumb-item>
    <a-breadcrumb-item><a href="">Application List</a></a-breadcrumb-item>
    <a-breadcrumb-item>An Application</a-breadcrumb-item>
  </a-breadcrumb>
</template>

2.带有图标的

在这里插入图片描述
图标放在文字前面

<template>
<a-breadcrumb>
  <a-breadcrumb-item href="">
    <a-icon type="home" />
  </a-breadcrumb-item>
  <a-breadcrumb-item href="">
    <a-icon type="user" />
    <span>Application List</span>
  </a-breadcrumb-item>
  <a-breadcrumb-item>
    Application
  </a-breadcrumb-item>
</a-breadcrumb>
</template>

3.分隔符

在这里插入图片描述
使用separator=">"可以自定义分隔符,或者使用slot="separator"自定义更复杂的分隔符

<template>
<div>
  <a-breadcrumb separator=">">
    <a-breadcrumb-item>Home</a-breadcrumb-item>
    <a-breadcrumb-item href="">Application Center</a-breadcrumb-item>
    <a-breadcrumb-item href="">Application List</a-breadcrumb-item>
    <a-breadcrumb-item>An Application</a-breadcrumb-item>
  </a-breadcrumb>
  <a-breadcrumb>
    <span slot="separator" style="color: red">></span>
    <a-breadcrumb-item>Home</a-breadcrumb-item>
    <a-breadcrumb-item href="">Application Center</a-breadcrumb-item>
    <a-breadcrumb-item href="">Application List</a-breadcrumb-item>
    <a-breadcrumb-item>An Application</a-breadcrumb-item>
  </a-breadcrumb>
</div>
</template>

4.vue-router

在这里插入图片描述
vue-router 进行结合使用。

<template>
<div>
  <a-breadcrumb :routes="routes">
    <template slot="itemRender" slot-scope="{route, params, routes, paths}">
      <span v-if="routes.indexOf(route) === routes.length - 1">
        {{route.breadcrumbName}}
      </span>
      <router-link v-else :to="`${basePath}/${paths.join('/')}`">
        {{route.breadcrumbName}}
      </router-link>
    </template>
  </a-breadcrumb>
  <br/>
  {{$route.path}}
</div>
</template>
<script>
  export default {
    data(){
      const { lang } = this.$route.params
      return {
        basePath: `/${lang}/components/breadcrumb`,
        routes: [{
          path: 'index',
          breadcrumbName: '首页'
        }, {
          path: 'first',
          breadcrumbName: '一级面包屑'
        }, {
          path: 'second',
          breadcrumbName: '当前页面'
        }],
      }
    },
  }
</script>

API

参数 说明 类型 默认值
itemRender 自定义链接函数,和 vue-router 配置使用, 也可使用slot=“itemRender” 和 slot-scope="props" object -
params 路由的参数 ({route, params, routes, paths}) => vNode -
routes router 的路由栈信息 object[] -
separator 分隔符自定义 string|slot '/'

和 browserHistory 配合

和 vue-router 一起使用时,默认生成的 url 路径是带有 # 的,如果和 browserHistory 一起使用的话,你可以使用 itemRender 属性定义面包屑链接。

<template>
<a-breadcrumb :routes="routes">
  <template slot="itemRender" slot-scope="{route, params, routes, paths}">
    <span v-if="routes.indexOf(route) === routes.length - 1">
      {{route.breadcrumbName}}
    </span>
    <router-link v-else :to="paths.join('/')">
      {{route.breadcrumbName}}
    </router-link>
  </template>
</a-breadcrumb>
</template>
<script>
  export default {
    data(){
      return {
        routes: [{
          path: 'index',
          breadcrumbName: '首页'
        }, {
          path: 'first',
          breadcrumbName: '一级面包屑'
        }, {
          path: 'second',
          breadcrumbName: '当前页面'
        }],
      }
    },
  }
</script>
发布了43 篇原创文章 · 获赞 61 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43583693/article/details/102498293
今日推荐