Topic: VueJS tabs - unable to control current active tab via API

eladhr83 free asked 4 years ago


Expected behavior

Hi ,We are using the MDB vue tabs component and looking for an API to control the active tab .

Best, Elad.

Actual behavior

Resources (screenshots, code snippets etc.)


Magdalena Dembna staff answered 4 years ago


There is a working example below - but in order to use those functionalities you need to update your MDB Vue version - watcher for active prop has been added quite recently. Best regards, Magdalena

<template>

      <div>
    <mdb-tabs
      :active="active"
      tabs
      card
      @activeTab="active = $event"
      class="mb-5"
      :links="[{ text: 'Home' }, { text: 'Profile' }, { text: 'Contact' }]"
      :content="[
        `Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.`,
        `Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.`,
        `Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.`
      ]"
    />
    <button @click="prevTab()">prev</button>
    <button @click="nextTab()">next</button>
  </div>
</template>

<script>
import { mdbTabs } from "mdbvue";

export default {
  name: "TabPage",
  components: {
    mdbTabs
  },
  data() {
    return {
      active: 2
    };
  },
  methods: {
    prevTab() {
      this.active--;
    },

    nextTab() {
      this.active++;
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h4 {
  font-weight: bold;
}
</style>

eladhr83 free answered 4 years ago


Hey Magdelena,I have tried to switch the current tab index as it described in the API and it is still not working. I have added some code:

    <template>
      <mdb-tabs  :active="active"
        tabs
        color="default"
        class="mb-2"
        :links="[
          { text: 'Active' },
          { text: 'Dropdown', dropdown: true, dropdownItems: [{ text: 'Action' }, { text: 'Another action' }, { text: 'Something else here' }, { divider: true }, { text: 'Separeted link'}]},
          { text: 'Link' },
          { text: 'Disabled', disabled: true } ]"
      />
<button @click="prevTab()">prev</button>
<button @click="nextTab()">next</button>
    </template>
        <script>
        active = 0; 
        prevTab() {
             this.active--; 
        }

         nextTab() { 
            this.active++; 
        }
        </script>

once I click the prev/next the tab is not changed.This is a blocker for our development. can you help me?


Magdalena Dembna staff answered 4 years ago


https://mdbootstrap.com/docs/vue/components/tabs/ Everything is described in the API tab - you can control the active tab with active property and each time the value is been changed by user, the @activeTab event is emitted with the current value. Kind regards, Magdalena



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Vue
  • MDB Version: 6.2.0
  • Device: Desktop
  • Browser: chrome
  • OS: Ubuntu
  • Provided sample code: No
  • Provided link: No