Vue Tabs Component

1.5.0 · active · verified Sun Apr 19

The `vue-tabs-component` library provides a lightweight and accessible Vue component for effortlessly rendering tabbed interfaces within Vue 2 applications. Currently stable at version 1.5.0, the package sees periodic updates, with recent releases adding features like the `isDisabled` prop for individual tabs (v1.4.0) and an option to control URL fragment usage (v1.2.0). Its key differentiators include built-in persistence of the last-opened tab across page reloads, configurable via a `cache-lifetime` prop, and the ability to link directly to tabs using URL fragments. Importantly, it offers an option (`useUrlFragment: false`) to disable URL fragment modification, crucial for integration with client-side routers or when deploying multiple tab instances. The component is designed with accessibility in mind, adhering to the ARIA specification for tab interfaces, ensuring a robust user experience. It provides flexible registration methods, allowing developers to either register individual components or use it as a Vue plugin.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global registration and basic usage of the `<tabs>` and `<tab>` components with custom content, event handling, and options.

import Vue from 'vue';
import { Tabs, Tab } from 'vue-tabs-component'; // Alternatively: import VueTabsPlugin from 'vue-tabs-component'; Vue.use(VueTabsPlugin);

// Register components globally
Vue.component('tabs', Tabs);
Vue.component('tab', Tab);

new Vue({
  el: '#app',
  methods: {
    tabClicked(event) {
      console.log(`Tab clicked: ${event.tab.name}`);
    },
    tabChanged(event) {
      console.log(`Tab changed to: ${event.tab.name}`);
    }
  },
  template: `
    <div id="app">
      <tabs :options="{ useUrlFragment: false }" @clicked="tabClicked" @changed="tabChanged" cache-lifetime="10">
          <tab name="First Tab Example">
              <p>This is the content of the first tab, demonstrating basic functionality and event handling.</p>
          </tab>
          <tab name="Second Tab Example">
              <p>This tab showcases more content. You can also disable a tab using the :is-disabled prop.</p>
          </tab>
          <tab name="Disabled Tab" :is-disabled="true">
              <p>This content will be unavailable while :is-disabled prop set to true. Users cannot select this tab.</p>
          </tab>
          <tab id="custom-fragment-tab" name="Custom URL Fragment">
              <p>The URL fragment can be customized for direct linking. E.g., #custom-fragment-tab.</p>
          </tab>
      </tabs>
    </div>
  `
});

view raw JSON →