witTabs Tab Component
witTabs is a tab component based on Element Plus, used to manage visited route pages, supports multiple style themes, tab operations, and right-click menu functionality, deeply integrated with the routing system, providing a smooth page switching experience.
Usage Example
<template>
<div>
<!-- Basic usage -->
<witTabs />
<!-- Specify layout -->
<witTabs layout="vertical" />
</div>
</template>
<script lang="ts" setup>
// No additional configuration needed, component automatically integrates with routing system
</script>API
Component
| Property Name | Type | Default Value | Description |
|---|---|---|---|
layout | [String] | '' | Layout type, used to adapt to different page layouts |
Events
Component interacts through routing system and state management, does not directly expose event interfaces.
Features
1. Route Integration
- Automatically tracks route pages visited by users
- Supports tab management when route parameters change
- Automatically restores tab state on page refresh
2. Tab Operations
- Click to Switch: Click tab to quickly switch to corresponding route page
- Close Tab: Supports closing individual tabs (except pinned tabs)
- Right-click Menu: Provides rich right-click menu operations:
- Refresh current tab
- Close other tabs
- Close left tabs
- Close right tabs
- Close all tabs
3. Multiple Style Themes
Component supports four tab bar styles, controlled through global configuration theme.tabsBarStyle:
card: Card-style tabssmart: Smart-style tabssmooth: Smooth-style tabsrect: Rectangular tabs
4. Pinned Tabs
Pinned tabs can be set through route configuration meta.noClosable: true, users cannot close them.
5. Dropdown Menu
When there are too many tabs, provides dropdown menu for quick access to all tabs.
Tab Management Logic
- Initialization: When component mounts, automatically adds all route tabs configured as
noClosable - Route Listening: Listens for route changes, automatically adds newly visited route tabs
- Tab Switching: When clicking a tab, if it's not the currently active route, navigates to it
- Tab Closing:
- When closing current tab, automatically navigates to last visited tab
- When closing other tabs, keeps current tab and pinned tabs
- Page Refresh: Listens for page unload events, saves tab state, restores on page reload
Style Structure
Component uses Flex layout, mainly contains the following parts:
wit-tabs: Main containerwit-tabs-content: Tab content areawit-tabs-more: More tabs dropdown buttoncontextmenu: Right-click menu
Different style themes are distinguished through wit-tabs-content-{style} class names, achieving different visual effects.
TIP
- Component is deeply integrated with Vue Router, no need to manually manage tab data
- Tab bar style can be modified through global configuration
settingsStore.theme.tabsBarStyle - Pinned tabs need to set
meta.noClosable: truein route configuration - Component provides rich tab operation features, enhancing user experience
- Supports quick tab management operations through right-click menu
