Categories
Quasar

Developing Vue Apps with the Quasar Library — Tab Panel Options

Spread the love

Quasar is a popular Vue UI library for developing good looking Vue apps.

In this article, we’ll take a look at how to create Vue apps with the Quasar UI library.

Tab Panels

We can add tab panels with the q-tab-panel component.

For instance, we can write:

<!DOCTYPE html>
<html>
  <head>
    <link
      href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
      rel="stylesheet"
      type="text/css"
    />
  </head>
  <body class="body--dark">
    <script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
    <div id="q-app">
      <q-layout view="lHh Lpr lFf" container style="height: 100vh;">
        <div class="q-pa-md">
          <q-option-group
            v-model="panel"
            inline
            :options="[
              { label: 'Mails', value: 'mails' },
              { label: 'Alarms', value: 'alarms' },
              { label: 'Movies', value: 'movies' }
            ]"
          >
          </q-option-group>

          <q-tab-panels
            v-model="panel"
            animated
            class="shadow-2 rounded-borders"
          >
            <q-tab-panel name="mails">
              <div class="text-h6">Mails</div>
              Lorem ipsum
            </q-tab-panel>

            <q-tab-panel name="alarms">
              <div class="text-h6">Alarms</div>
              Lorem ipsum
            </q-tab-panel>

            <q-tab-panel name="movies">
              <div class="text-h6">Movies</div>
              Lorem ipsum
            </q-tab-panel>
          </q-tab-panels>
        </div>
      </q-layout>
    </div>
    <script>
      new Vue({
        el: "#q-app",
        data: {
          panel: "mails"
        }
      });
    </script>
  </body>
</html>

We can add q-tab-panels components with q-tab-panel inside.

The v-model binds to the name value of the q-tab-panel , which is set with the q-option-group .

We can change the color with the class prop of the q-tab-panels component:

<!DOCTYPE html>
<html>
  <head>
    <link
      href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
      rel="stylesheet"
      type="text/css"
    />
  </head>
  <body class="body--dark">
    <script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
    <div id="q-app">
      <q-layout view="lHh Lpr lFf" container style="height: 100vh;">
        <div class="q-pa-md">
          <q-option-group
            v-model="panel"
            inline
            :options="[
              { label: 'Mails', value: 'mails' },
              { label: 'Alarms', value: 'alarms' },
              { label: 'Movies', value: 'movies' }
            ]"
          >
          </q-option-group>

          <q-tab-panels v-model="panel" animated class="bg-primary text-white">
            <q-tab-panel name="mails">
              <div class="text-h6">Mails</div>
              Lorem ipsum
            </q-tab-panel>

            <q-tab-panel name="alarms">
              <div class="text-h6">Alarms</div>
              Lorem ipsum
            </q-tab-panel>

            <q-tab-panel name="movies">
              <div class="text-h6">Movies</div>
              Lorem ipsum
            </q-tab-panel>
          </q-tab-panels>
        </div>
      </q-layout>
    </div>
    <script>
      new Vue({
        el: "#q-app",
        data: {
          panel: "mails"
        }
      });
    </script>
  </body>
</html>

Tab Panel Transitions

We can change the tab panel’s transitions with the animated and transition-prev and transition-next props:

<!DOCTYPE html>
<html>
  <head>
    <link
      href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.min.css"
      rel="stylesheet"
      type="text/css"
    />
  </head>
  <body class="body--dark">
    <script src="https://cdn.jsdelivr.net/npm/vue@^2.0.0/dist/vue.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/quasar@1.12.13/dist/quasar.umd.min.js"></script>
    <div id="q-app">
      <q-layout view="lHh Lpr lFf" container style="height: 100vh;">
        <div class="q-pa-md">
          <q-option-group
            v-model="panel"
            inline
            :options="[
              { label: 'Mails', value: 'mails' },
              { label: 'Alarms', value: 'alarms' },
              { label: 'Movies', value: 'movies' }
            ]"
          >
          </q-option-group>

          <q-tab-panels
            v-model="panel"
            animated
            transition-prev="scale"
            transition-next="scale"
          >
            <q-tab-panel name="mails">
              <div class="text-h6">Mails</div>
              Lorem ipsum
            </q-tab-panel>

            <q-tab-panel name="alarms">
              <div class="text-h6">Alarms</div>
              Lorem ipsum
            </q-tab-panel>

            <q-tab-panel name="movies">
              <div class="text-h6">Movies</div>
              Lorem ipsum
            </q-tab-panel>
          </q-tab-panels>
        </div>
      </q-layout>
    </div>
    <script>
      new Vue({
        el: "#q-app",
        data: {
          panel: "mails"
        }
      });
    </script>
  </body>
</html>

transition-prev is applied when we leave a tab panel.

And transition-next is applied when we enter a tab panel.

Conclusion

We can add tab panels into our Vue app with the Quasar library.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *