NavTabs 导航条

快速的数据化配置一个导航条,常用于后台管理系统中。

基础使用

在下面的例子中,基于后台系统做了一个简单的架子,便于理解该组件。

Tab 标签栏上右键操作可打开导航功能菜单。

若想保持刷新保留 tabs,可通过 localStorage 等将数据持久化存储在本地。

点击查看代码
<template>
  <ElContainer class="common-layout">
    <ElAside width="100px">Aside</ElAside>
    <ElContainer>
      <ElHeader>Header</ElHeader>

      <AgelNavTabs
        v-model:tabs="tabs"
        :route-path="route.path"
        home-path="/"
        more
        fixed
        reload
        zoom
        @path-change="pathChange"
        @reload="reload"
      >
        <template #menu="{ item }">
          <div @click="(fullScreen = true)">
            <AgelIcon icon="FullScreen"></AgelIcon>
            <span>zoom In</span>
          </div>
        </template>
      </AgelNavTabs>

      <ElMain v-loading="!keepAlive" :class="{ 'full-screen': fullScreen }">
        <RouterView v-if="keepAlive">
          <TableSlot class="w100" style="padding: 0px; margin: 0px" size="mini"></TableSlot>
        </RouterView>
      </ElMain>
    </ElContainer>

    <AgelIcon v-show="fullScreen" icon="CircleCloseFilled" :size="30" class="close" @click="(fullScreen = false)">
    </AgelIcon>
  </ElContainer>
</template>

<script setup lang="ts">
import { ref, watch, nextTick } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import TableSlot from './tableSlot.vue'

const route = useRoute()
const router = useRouter()

const fullScreen = ref(false)
const keepAlive = ref(true)
const tabs = ref([
  { title: '首页', icon: 'HomeFilled', path: '/' },
  { title: 'Menu 菜单', path: '/component/menu' }
])

watch(
  () => route.path,
  () => {
    const index = tabs.value.findIndex((item) => item.path === route.path)
    if (index == -1) {
      tabs.value.push({
        path: route.path,
        icon: route.meta.icon as string,
        title: route.meta.title as string
      })
    }
  },
  { immediate: true }
)

function pathChange(path: string) {
  router.push({ path })
}

function reload() {
  keepAlive.value = false
  nextTick(() => (keepAlive.value = true))
}
</script>






 
 
 
 
 
 
 
 
 





























































属性

属性类型默认值说明
v-model:tabsTab[]-选项卡配置,必须
routePathstring-当前路由 path,必须
homePathstring-首页 path,该 tab 将置顶不会被移除
morebooleantrue更多按钮
fixedboolean-固定菜单
reloadboolean-重载菜单
isBackgroundboolean-背景样式导航条

TabProps

属性类型默认值说明
titlestring-tab 名称,必须
pathindex-路由地址,必须
iconstring-tab 图标或图片地址
fixedboolean-是否固定

事件

名称参数说明
path-changepathpath 发生变化时
reload-点击重新加载菜单时

插槽

名称插槽作用域说明
menu{ item }下拉菜单
Last Updated:
Contributors: agrass, liujianfeng