Home

Awesome

vue3-tabs

A touch swipe tab for vue 3.

Demo

Demo

Demo Code

Install

yarn add vue3-tabs
npm i --save vue3-tabs

Register Global Component

import { createApp } from 'vue';
import App from './App.vue'
import Tabs from 'vue3-tabs';

const app = createApp(App);
app.use(Tabs);
app.mount('#app')

Register Local Component

import { Tabs, Tab, TabPanels, TabPanel } from 'vue3-tabs';

export default {
  components: {
    Tabs,
    Tab,
    TabPanels,
    TabPanel
  },
};

Example

<template>
  <h3>Basic Example</h3>
  <tabs
    v-model="selectedTab"
  >
    <tab
      class="tab"
      v-for="(tab, i) in tabs"
      :key="`t${i}`"
      :val="tab"
      :label="tab"
      :indicator="true"
    />
  </tabs>
  <tab-panels
    v-model="selectedTab"
    :animate="true"
  >
    <tab-panel
      v-for="(tab, i) in tabs"
      :key="`tp${i}`"
      :val="tab"
    >
      {{ tab }}
    </tab-panel>
  </tab-panels>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs } from 'vue';

const tabs = ['A', 'B', 'C'];

export default defineComponent({
  name: 'Example',
  setup() {
    const state = reactive({
      selectedTab: tabs[1]
    });
    return {
      tabs,
      ...toRefs(state)
    };
  }
});
</script>

<style scoped>
.tab {
  padding: 10px 20px;
}
</style>

Components

Tabs

Props
NameTypeRequiredDefaultNotes
:model-value | v-modelstring | number | nullyesnullvalue emit
Events
NameDescription
@update:modelValueevent emit when tab change
Slots
NameTagDescription
v-slot:default<tab /><tab /> as children

Tab

Props
NameTypeRequiredDefaultNotes
:valstring | numberyesnullvalue to indicate active
:labelstringnonulllabel
:indicatorbooleannofalseshow default active indicator

TabPanels

Props
NameTypeRequiredDefaultNotes
:model-value | v-modelstring | number | nullyesnullvalue emit
:animatebooleannofalsesmooth change effect<br>not working with ios
:swipeablebooleannofalseswipe to change tab
:thresholdnumberno50minimum pixel to swipe to change tab<br>only work when swipeable = true
Events
NameDescription
@update:modelValueevent emit when tab change
@on-animation-endevent emit switch animation end
Slots
NameTagDescription
v-slot:default<tab-panel /><tab-panel /> as children

TabPanel

Props
NameTypeRequiredDefaultNotes
:valstring | numberyesnullvalue to indicate active

Project setup

yarn

Compiles and hot-reloads for development

yarn serve

Compiles and minifies for production

yarn build

Customize configuration

See Configuration Reference.