Press "Enter" to skip to content

Material UI Touch-Swipe Tabs Component for Vue 3

Vue3 tabs is a mobile-friendly tabs plugin that allows users to swipe between tabbed content via a quick touch swipe.

simple tabs component codesandbox, material ui tabs example, best react tabs component, responsive tabs material ui, material ui dynamic tabs, vertical tabs in bootstrap

How to make use of it:

Install and download:

# Yarn
$ yarn add vue3-tabs

# NPM
$ npm i vue3-tabs --save

1. Import and register tabs component.

// globally
import { createApp } from 'vue';
import App from './App.vue'
import Tabs from 'vue3-tabs';
const app = createApp(App);
app.use(Tabs);
app.mount('#app');
// locally
import { Tabs, Tab, TabPanels, TabPanel } from 'vue3-tabs';
export default {
  components: {
    Tabs,
    Tab,
    TabPanels,
    TabPanel
  },
};

2. Create a basic tabs component.

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

3. Create a custom tabs component.

<template>
  <h3>Custom Example</h3>
  <tabs
    v-model="selectedTab"
  >
    <tab
      v-for="(tab, i) in tabs"
      :key="`t${i}`"
      :val="tab.value"
    >
      <div
        :style="{'border-color': getActive(tab.value) ? tab.color : '', color: getActive(tab.value) ? tab.color : ''}"
        :class="{'active-tab': getActive(tab.value)}"
        class="tab"
      >
        {{ tab.label }}
      </div>
    </tab>
  </tabs>
  <tab-panels
    v-model="selectedTab"
    :animate="true"
    :swipeable="true"
    class="tab-panels"
  >
    <tab-panel
      v-for="(tab, i) in tabs"
      :key="`tp${i}`"
      :val="tab.value"
      class="tab-panel"
      :style="`background: ${tab.color}; color: white;`"
    >
      <div>
        {{ tab.description }}
      </div>
    </tab-panel>
  </tab-panels>
</template>
import { defineComponent, reactive, toRefs } from 'vue';
const tabs = [{
  label: 'Tab 1',
  value: 1,
  description: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book`,
  color: 'blue'
}, {
  label: 'Tab 2',
  value: 2,
  description: `It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy`,
  color: 'red'
}, {
  label: 'Tab 3',
  value: 3,
  description: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old',
  color: 'grey'
}];
export default defineComponent({
  name: 'Example',
  setup() {
    const state = reactive({
      selectedTab: tabs[0].value
    });
    function getActive(tab: string | number) {
      return state.selectedTab === tab;
    }
    return {
      tabs,
      getActive,
      ...toRefs(state)
    };
  }
});

Touch-enabled Tabs Component, vue3 tabs Plugin/Github


See Demo And Download

Official Website(HJ29): Click Here

This superior jQuery/javascript plugin is developed by HJ29. For extra advanced usage, please go to the official website.

Be First to Comment

    Leave a Reply

    Your email address will not be published.