Breadcrumb面包屑

Breadcrumb 面包屑

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

何时使用

  • 当系统拥有超过两级以上的层级结构时;

  • 当需要告知用户『你在哪里』时;

  • 当需要向上导航的功能时。

代码演示

基本

最简单的用法。

<​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>

其它路由

和 vue-router 进行结合使用。

<​template>  <​div>    <​a-breadcrumb :routes="routes">      <​template #itemRender="{ route, 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 lang="ts">import { defineComponent, ref } from 'vue';interface Route {  path: string;  breadcrumbName: string;  children?: Array<{    path: string;    breadcrumbName: string;  }>;}export default defineComponent({  setup() {    const routes = ref<​Route[]>([      {        path: 'index',        breadcrumbName: 'home',      },      {        path: 'first',        breadcrumbName: 'first',        children: [          {            path: '/general',            breadcrumbName: 'General',          },          {            path: '/layout',            breadcrumbName: 'Layout',          },          {            path: '/navigation',            breadcrumbName: 'Navigation',          },        ],      },      {        path: 'second',        breadcrumbName: 'second',      },    ]);    return {      basePath: '/components/breadcrumb',      routes,    };  },});<​/script>

分隔符

使用 Breadcrumb.Separator 可以自定义分隔符。

<​template>  <​a-breadcrumb separator="">    <​a-breadcrumb-item>Location<​/a-breadcrumb-item>    <​a-breadcrumb-separator>:<​/a-breadcrumb-separator>    <​a-breadcrumb-item href="">Application Center<​/a-breadcrumb-item>    <​a-breadcrumb-separator />    <​a-breadcrumb-item href="">Application List<​/a-breadcrumb-item>    <​a-breadcrumb-separator />    <​a-breadcrumb-item>An Application<​/a-breadcrumb-item>  <​/a-breadcrumb><​/template>

带下拉菜单的面包屑

面包屑支持下拉菜单。

<​template>  <​a-breadcrumb>    <​a-breadcrumb-item>Ant Design Vue<​/a-breadcrumb-item>    <​a-breadcrumb-item><​a href="">Component<​/a><​/a-breadcrumb-item>    <​a-breadcrumb-item>      <​a href="">General<​/a>      <​template #overlay>        <​a-menu>          <​a-menu-item>            <​a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">General<​/a>          <​/a-menu-item>          <​a-menu-item>            <​a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">Layout<​/a>          <​/a-menu-item>          <​a-menu-item>            <​a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">Navigation<​/a>          <​/a-menu-item>        <​/a-menu>      <​/template>    <​/a-breadcrumb-item>    <​a-breadcrumb-item>Button<​/a-breadcrumb-item>  <​/a-breadcrumb><​/template>

分隔符

用separator=">"可以自定义分隔符,或者使用slot=”separator”自定义更复杂的分隔符

<​template>  <​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>    <​template #separator><​span style="color: red">><​/span><​/template>    <​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><​/template>

带有图标的

图标放在文字前面。

<​template>  <​a-breadcrumb>    <​a-breadcrumb-item href="">      <​home-outlined />    <​/a-breadcrumb-item>    <​a-breadcrumb-item href="">      <​user-outlined />      <​span>Application List<​/span>    <​/a-breadcrumb-item>    <​a-breadcrumb-item>Application<​/a-breadcrumb-item>  <​/a-breadcrumb><​/template><​script lang="ts">import { defineComponent } from 'vue';import { HomeOutlined, UserOutlined } from '@ant-design/icons-vue';export default defineComponent({  components: {    HomeOutlined,    UserOutlined,  },});<​/script>

API

参数 说明 类型 可选值 默认值
itemRender 自定义链接函数,和 vue-router 配置使用, 也可使用 #itemRender=”props” ({route, params, routes, paths}) => vNode -
params 路由的参数 object -
routes router 的路由栈信息 routes[] -

| separator | 分隔符自定义 | string|slot | | ‘/‘ | |---|---|---|---|---|

参数 参数 类型 默认值 版本
href 链接的目的地 string - 1.5.0

| overlay | 下拉菜单的内容 | Menu | () => Menu | - | 1.5.0 | |---|---|---|---|---|

事件

事件名称 说明 回调参数 版本
click 单击事件 (e:MouseEvent)=>void -
参数 类型 默认值 版本
- - - -

注意:在使用 Breadcrumb.Separator 时,其父组件的分隔符必须设置为 separator="",否则会出现父组件默认的分隔符。

routes

interface Route {  path: string;  breadcrumbName: string;  children?: Array<{    path: string;    breadcrumbName: string;  }>;}

和 browserHistory 配合

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

<​template>  <​a-breadcrumb :routes="routes">    <​template #itemRender="{ 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 lang="ts">import { defineComponent, ref } from 'vue';interface Route {  path: string;  breadcrumbName: string;  children?: Array<{    path: string;    breadcrumbName: string;  }>;}export default defineComponent({  setup () {    const routes = ref<​Route[]>([      {        path: 'index',        breadcrumbName: 'home',      },      {        path: 'first',        breadcrumbName: 'first',        children: [          {            path: '/general',            breadcrumbName: 'General',          },          {            path: '/layout',            breadcrumbName: 'Layout',          },          {            path: '/navigation',            breadcrumbName: 'Navigation',          },        ],      },      {        path: 'second',        breadcrumbName: 'second',      },    ]);    return {      routes,    }  }});<​/script>