- Breadcrumb面包屑
- 何时使用
- 代码演示
- 基本
- 带有图标的
- 分隔符
- vue-router
- API
- 和 browserHistory 配合
- 和 browserHistory 配合
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>

带有图标的
图标放在文字前面
<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>

分隔符
使用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>

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.paramsreturn {basePath: `/${lang}/components/breadcrumb`,routes: [{path: 'index',breadcrumbName: '首页'}, {path: 'first',breadcrumbName: '一级面包屑'}, {path: 'second',breadcrumbName: '当前页面'}],}},}</script>
API
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| itemRender | 自定义链接函数,和 vue-router 配置使用, 也可使用slot="itemRender" 和 slot-scope="props" | ({route, params, routes, paths}) => vNode | - | |
| params | 路由的参数 | object | - | |
| 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>
