Skip to content
On this page

导航菜单 Menu

为网站提供导航功能的菜单。

顶栏

导航菜单默认为垂直模式,通过mode属性可以使导航菜单变更为水平模式。另外,在菜单中通过submenu组件可以生成二级菜单。Menu 还提供了background-colortext-coloractive-text-color,分别用于设置菜单的背景色、菜单的文字颜色和当前激活菜单的文字颜色

<template>
  <div>
    <b-menu
      :default-active="activeIndex"
      class="b-menu-demo"
      mode="horizontal"
      style="padding-left: 55px"
      @select="handleSelect"
    >
      <b-menu-item index="1">处理中心</b-menu-item>
      <b-submenu index="2">
        <template #title>我的工作台</template>
        <b-menu-item index="2-1">选项1</b-menu-item>
        <b-menu-item index="2-2">选项2</b-menu-item>
        <b-menu-item index="2-3">选项3</b-menu-item>
        <b-submenu index="2-4">
          <template #title>选项4</template>
          <b-menu-item index="2-4-1">选项1</b-menu-item>
          <b-menu-item index="2-4-2">选项2</b-menu-item>
          <b-menu-item index="2-4-3">选项3</b-menu-item>
        </b-submenu>
      </b-submenu>
      <b-menu-item index="3" disabled>消息中心</b-menu-item>
      <b-menu-item index="4">
        <a href="https://wangbin3162.github.io/bin-ui-design/" target="_blank">文档外链</a>
      </b-menu-item>
    </b-menu>
    <b-divider />
    <b-menu
      :default-active="activeIndex2"
      class="b-menu-demo"
      mode="horizontal"
      background-color="#001529"
      text-color="#fff"
      active-text-color="#ffd04b"
      style="padding-left: 55px"
      @select="handleSelect"
    >
      <b-menu-item index="1">处理中心</b-menu-item>
      <b-submenu index="2">
        <template #title>我的工作台</template>
        <b-menu-item index="2-1">选项1</b-menu-item>
        <b-menu-item index="2-2">选项2</b-menu-item>
        <b-menu-item index="2-3">选项3</b-menu-item>
        <b-submenu index="2-4">
          <template #title>选项4</template>
          <b-menu-item index="2-4-1">选项1</b-menu-item>
          <b-menu-item index="2-4-2">选项2</b-menu-item>
          <b-menu-item index="2-4-3">选项3</b-menu-item>
        </b-submenu>
      </b-submenu>
      <b-menu-item index="3" disabled>消息中心</b-menu-item>
      <b-menu-item index="4">
        <a href="https://wangbin3162.github.io/bin-ui-design/" target="_blank">文档外链</a>
      </b-menu-item>
    </b-menu>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const activeIndex = ref('1')
const activeIndex2 = ref('1')

function handleSelect(key, keyPath) {
  console.log(key, keyPath)
}
</script>
<template>
  <div>
    <b-menu
      :default-active="activeIndex"
      class="b-menu-demo"
      mode="horizontal"
      style="padding-left: 55px"
      @select="handleSelect"
    >
      <b-menu-item index="1">处理中心</b-menu-item>
      <b-submenu index="2">
        <template #title>我的工作台</template>
        <b-menu-item index="2-1">选项1</b-menu-item>
        <b-menu-item index="2-2">选项2</b-menu-item>
        <b-menu-item index="2-3">选项3</b-menu-item>
        <b-submenu index="2-4">
          <template #title>选项4</template>
          <b-menu-item index="2-4-1">选项1</b-menu-item>
          <b-menu-item index="2-4-2">选项2</b-menu-item>
          <b-menu-item index="2-4-3">选项3</b-menu-item>
        </b-submenu>
      </b-submenu>
      <b-menu-item index="3" disabled>消息中心</b-menu-item>
      <b-menu-item index="4">
        <a href="https://wangbin3162.github.io/bin-ui-design/" target="_blank">文档外链</a>
      </b-menu-item>
    </b-menu>
    <b-divider />
    <b-menu
      :default-active="activeIndex2"
      class="b-menu-demo"
      mode="horizontal"
      background-color="#001529"
      text-color="#fff"
      active-text-color="#ffd04b"
      style="padding-left: 55px"
      @select="handleSelect"
    >
      <b-menu-item index="1">处理中心</b-menu-item>
      <b-submenu index="2">
        <template #title>我的工作台</template>
        <b-menu-item index="2-1">选项1</b-menu-item>
        <b-menu-item index="2-2">选项2</b-menu-item>
        <b-menu-item index="2-3">选项3</b-menu-item>
        <b-submenu index="2-4">
          <template #title>选项4</template>
          <b-menu-item index="2-4-1">选项1</b-menu-item>
          <b-menu-item index="2-4-2">选项2</b-menu-item>
          <b-menu-item index="2-4-3">选项3</b-menu-item>
        </b-submenu>
      </b-submenu>
      <b-menu-item index="3" disabled>消息中心</b-menu-item>
      <b-menu-item index="4">
        <a href="https://wangbin3162.github.io/bin-ui-design/" target="_blank">文档外链</a>
      </b-menu-item>
    </b-menu>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const activeIndex = ref('1')
const activeIndex2 = ref('1')

function handleSelect(key, keyPath) {
  console.log(key, keyPath)
}
</script>

侧栏

垂直菜单,可内嵌子菜单。通过b-menu-item-group组件可以实现菜单进行分组,分组名可以通过title属性直接设定,也可以通过具名 slot 来设定。

默认颜色
自定义颜色
<template>
  <b-row class="tac">
    <b-col :span="12">
      <h5 style="margin-bottom: 10px">默认颜色</h5>
      <b-menu
        default-active="2"
        class="b-menu-vertical-demo border"
        @open="handleOpen"
        @close="handleClose"
      >
        <b-submenu index="1">
          <template #title>
            <b-icon name="location-fill"></b-icon>
            <span>导航一</span>
          </template>
          <b-menu-item-group>
            <template #title>分组一</template>
            <b-menu-item index="1-1">选项1</b-menu-item>
            <b-menu-item index="1-2">选项2</b-menu-item>
          </b-menu-item-group>
          <b-menu-item-group title="分组2">
            <b-menu-item index="1-3">选项3</b-menu-item>
          </b-menu-item-group>
          <b-submenu index="1-4">
            <template #title>选项4</template>
            <b-menu-item index="1-4-1">选项1</b-menu-item>
          </b-submenu>
        </b-submenu>
        <b-menu-item index="2">
          <b-icon name="appstore-fill"></b-icon>
          <template #title>导航二</template>
        </b-menu-item>
        <b-menu-item index="3" disabled>
          <b-icon name="file-text"></b-icon>
          <template #title>导航三</template>
        </b-menu-item>
        <b-menu-item index="4">
          <b-icon name="setting-fill"></b-icon>
          <template #title>导航四</template>
        </b-menu-item>
      </b-menu>
    </b-col>
    <b-col :span="12">
      <h5 style="margin-bottom: 10px">自定义颜色</h5>
      <b-menu
        :unique-opened="true"
        default-active="2"
        class="b-menu-vertical-demo"
        background-color="#495662"
        text-color="#fff"
        active-text-color="#ffd04b"
        @open="handleOpen"
        @close="handleClose"
      >
        <b-submenu index="1">
          <template #title>
            <b-icon name="location-fill"></b-icon>
            <span>导航一</span>
          </template>
          <b-menu-item-group>
            <template #title>分组一</template>
            <b-menu-item index="1-1">选项1</b-menu-item>
            <b-menu-item index="1-2">选项2</b-menu-item>
          </b-menu-item-group>
          <b-menu-item-group title="分组2">
            <b-menu-item index="1-3">选项3</b-menu-item>
          </b-menu-item-group>
          <b-submenu index="1-4">
            <template #title>选项4</template>
            <b-menu-item index="1-4-1">选项1</b-menu-item>
          </b-submenu>
        </b-submenu>
        <b-menu-item index="2">
          <b-icon name="appstore-fill"></b-icon>
          <template #title>导航二</template>
        </b-menu-item>
        <b-menu-item index="3" disabled>
          <b-icon name="file-text"></b-icon>
          <template #title>导航三</template>
        </b-menu-item>
        <b-menu-item index="4">
          <b-icon name="setting-fill"></b-icon>
          <template #title>导航四</template>
        </b-menu-item>
      </b-menu>
    </b-col>
  </b-row>
</template>

<script setup lang="ts">
function handleOpen(key, keyPath) {
  console.log(key, keyPath)
}
function handleClose(key, keyPath) {
  console.log(key, keyPath)
}
</script>

<style scoped>
.b-menu-vertical-demo {
  width: 240px;
  border-right: 1px solid #f0f0f0;
}
</style>
<template>
  <b-row class="tac">
    <b-col :span="12">
      <h5 style="margin-bottom: 10px">默认颜色</h5>
      <b-menu
        default-active="2"
        class="b-menu-vertical-demo border"
        @open="handleOpen"
        @close="handleClose"
      >
        <b-submenu index="1">
          <template #title>
            <b-icon name="location-fill"></b-icon>
            <span>导航一</span>
          </template>
          <b-menu-item-group>
            <template #title>分组一</template>
            <b-menu-item index="1-1">选项1</b-menu-item>
            <b-menu-item index="1-2">选项2</b-menu-item>
          </b-menu-item-group>
          <b-menu-item-group title="分组2">
            <b-menu-item index="1-3">选项3</b-menu-item>
          </b-menu-item-group>
          <b-submenu index="1-4">
            <template #title>选项4</template>
            <b-menu-item index="1-4-1">选项1</b-menu-item>
          </b-submenu>
        </b-submenu>
        <b-menu-item index="2">
          <b-icon name="appstore-fill"></b-icon>
          <template #title>导航二</template>
        </b-menu-item>
        <b-menu-item index="3" disabled>
          <b-icon name="file-text"></b-icon>
          <template #title>导航三</template>
        </b-menu-item>
        <b-menu-item index="4">
          <b-icon name="setting-fill"></b-icon>
          <template #title>导航四</template>
        </b-menu-item>
      </b-menu>
    </b-col>
    <b-col :span="12">
      <h5 style="margin-bottom: 10px">自定义颜色</h5>
      <b-menu
        :unique-opened="true"
        default-active="2"
        class="b-menu-vertical-demo"
        background-color="#495662"
        text-color="#fff"
        active-text-color="#ffd04b"
        @open="handleOpen"
        @close="handleClose"
      >
        <b-submenu index="1">
          <template #title>
            <b-icon name="location-fill"></b-icon>
            <span>导航一</span>
          </template>
          <b-menu-item-group>
            <template #title>分组一</template>
            <b-menu-item index="1-1">选项1</b-menu-item>
            <b-menu-item index="1-2">选项2</b-menu-item>
          </b-menu-item-group>
          <b-menu-item-group title="分组2">
            <b-menu-item index="1-3">选项3</b-menu-item>
          </b-menu-item-group>
          <b-submenu index="1-4">
            <template #title>选项4</template>
            <b-menu-item index="1-4-1">选项1</b-menu-item>
          </b-submenu>
        </b-submenu>
        <b-menu-item index="2">
          <b-icon name="appstore-fill"></b-icon>
          <template #title>导航二</template>
        </b-menu-item>
        <b-menu-item index="3" disabled>
          <b-icon name="file-text"></b-icon>
          <template #title>导航三</template>
        </b-menu-item>
        <b-menu-item index="4">
          <b-icon name="setting-fill"></b-icon>
          <template #title>导航四</template>
        </b-menu-item>
      </b-menu>
    </b-col>
  </b-row>
</template>

<script setup lang="ts">
function handleOpen(key, keyPath) {
  console.log(key, keyPath)
}
function handleClose(key, keyPath) {
  console.log(key, keyPath)
}
</script>

<style scoped>
.b-menu-vertical-demo {
  width: 240px;
  border-right: 1px solid #f0f0f0;
}
</style>

折叠

<template>
  <div>
    <b-button-group v-model="isCollapse" style="margin-bottom: 20px">
      <b-button :type="isCollapse ? 'default' : 'primary'" @click="isCollapse = false">
        展开
      </b-button>
      <b-button :type="isCollapse ? 'primary' : 'default'" @click="isCollapse = true">
        收起
      </b-button>
    </b-button-group>

    <b-menu
      style="width: 240px"
      default-active="1-4-1"
      :collapse="isCollapse"
      background-color="#232324"
      text-color="#fff"
      active-text-color="#ffd04b"
      class="b-menu-vertical-demo border"
      @open="handleOpen"
      @close="handleClose"
    >
      <b-submenu index="1">
        <template #title>
          <b-icon name="location-fill"></b-icon>
          <span>导航一</span>
        </template>
        <b-menu-item-group>
          <template #title>分组一</template>
          <b-menu-item index="1-1">选项1</b-menu-item>
          <b-menu-item index="1-2">选项2</b-menu-item>
        </b-menu-item-group>
        <b-menu-item-group title="分组2">
          <b-menu-item index="1-3">选项3</b-menu-item>
        </b-menu-item-group>
        <b-submenu index="1-4">
          <template #title>选项4</template>
          <b-menu-item index="1-4-1">选项1</b-menu-item>
        </b-submenu>
      </b-submenu>
      <b-menu-item index="2">
        <b-icon name="appstore-fill"></b-icon>
        <template #title>导航二</template>
      </b-menu-item>
      <b-menu-item index="3" disabled>
        <b-icon name="file-text"></b-icon>
        <template #title>导航三</template>
      </b-menu-item>
      <b-menu-item index="4">
        <b-icon name="setting-fill"></b-icon>
        <template #title>导航四</template>
      </b-menu-item>
    </b-menu>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const isCollapse = ref(false)

function handleOpen(key, keyPath) {
  console.log(key, keyPath)
}
function handleClose(key, keyPath) {
  console.log(key, keyPath)
}
</script>

<style scoped>
.b-menu-vertical-demo {
  width: 240px;
  border-right: 1px solid #f0f0f0;
}
</style>
<template>
  <div>
    <b-button-group v-model="isCollapse" style="margin-bottom: 20px">
      <b-button :type="isCollapse ? 'default' : 'primary'" @click="isCollapse = false">
        展开
      </b-button>
      <b-button :type="isCollapse ? 'primary' : 'default'" @click="isCollapse = true">
        收起
      </b-button>
    </b-button-group>

    <b-menu
      style="width: 240px"
      default-active="1-4-1"
      :collapse="isCollapse"
      background-color="#232324"
      text-color="#fff"
      active-text-color="#ffd04b"
      class="b-menu-vertical-demo border"
      @open="handleOpen"
      @close="handleClose"
    >
      <b-submenu index="1">
        <template #title>
          <b-icon name="location-fill"></b-icon>
          <span>导航一</span>
        </template>
        <b-menu-item-group>
          <template #title>分组一</template>
          <b-menu-item index="1-1">选项1</b-menu-item>
          <b-menu-item index="1-2">选项2</b-menu-item>
        </b-menu-item-group>
        <b-menu-item-group title="分组2">
          <b-menu-item index="1-3">选项3</b-menu-item>
        </b-menu-item-group>
        <b-submenu index="1-4">
          <template #title>选项4</template>
          <b-menu-item index="1-4-1">选项1</b-menu-item>
        </b-submenu>
      </b-submenu>
      <b-menu-item index="2">
        <b-icon name="appstore-fill"></b-icon>
        <template #title>导航二</template>
      </b-menu-item>
      <b-menu-item index="3" disabled>
        <b-icon name="file-text"></b-icon>
        <template #title>导航三</template>
      </b-menu-item>
      <b-menu-item index="4">
        <b-icon name="setting-fill"></b-icon>
        <template #title>导航四</template>
      </b-menu-item>
    </b-menu>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const isCollapse = ref(false)

function handleOpen(key, keyPath) {
  console.log(key, keyPath)
}
function handleClose(key, keyPath) {
  console.log(key, keyPath)
}
</script>

<style scoped>
.b-menu-vertical-demo {
  width: 240px;
  border-right: 1px solid #f0f0f0;
}
</style>
参数说明类型可选值默认值
mode模式stringhorizontal / verticalvertical
collapse是否水平折叠收起菜单(仅在 mode 为 vertical 时可用)booleanfalse
background-color菜单的背景色(仅支持 hex 格式)string#ffffff
text-color菜单的文字颜色(仅支持 hex 格式)stringrgba(0,0,0,.65)
active-text-color当前激活菜单的文字颜色(仅支持 hex 格式)string#1089ff
default-active当前激活菜单的 indexstring
default-openeds当前打开的 sub-menu 的 index 的数组Array
unique-opened是否只保持一个子菜单的展开booleanfalse
menu-trigger子菜单打开的触发方式(只在 mode 为 horizontal 时有效)stringhover / clickhover
router是否使用 vue-router 的模式,启用该模式会在激活导航时以 index 作为 path 进行路由跳转booleanfalse
方法名称说明参数
open展开指定的 sub-menuindex: 需要打开的 sub-menu 的 index
close收起指定的 sub-menuindex: 需要收起的 sub-menu 的 index
事件名称说明回调参数
select菜单激活回调index: 选中菜单项的 index, indexPath: 选中菜单项的 index path
opensub-menu 展开的回调index: 打开的 sub-menu 的 index, indexPath: 打开的 sub-menu 的 index path
closesub-menu 收起的回调index: 收起的 sub-menu 的 index, indexPath: 收起的 sub-menu 的 index path
参数说明类型可选值默认值
index唯一标志string/nullnull
popper-class弹出菜单的自定义类名string
show-timeout展开 sub-menu 的延时number300
hide-timeout收起 sub-menu 的延时number300
disabled是否禁用booleanfalse
popper-append-to-body是否将弹出菜单插入至 body 元素。在菜单的定位出现问题时,可尝试修改该属性boolean一级子菜单:true / 非一级子菜单:false
参数说明类型可选值默认值
index唯一标志string
routeVue Router 路径对象Object
disabled是否禁用booleanfalse
参数说明类型可选值默认值
title分组标题string