I would like to present to you a quick tip about working with the tabs component in Vuetify.js. I sometimes need to navigate to a specific tab in the application or want to share a direct tab link with a collaborator.
In order to achieve this, we need to store the information about the current tab in the URL in the browser address bar. A canonical solution involves using nested routes, but sometimes it’s an overkill to create a separate child page for each tab. Thankfully there’s a simpler approach that I quite often end up using.
First let’s look at a simple tabs component…
If the number of rows grows too large, or we are viewing the site on a mobile device, the table may not fit on the screen. If this happens, it can be unclear which column represents what information.
One solution to this problem is to always keep the table header visible when scrolling, and there are a couple of ways we can make this happen.
The simplest solution is to use the data table’s built-in
fixed-header property, which only works if height of the table is defined (see v-data-table documentation for more info):
<v-data-table :headers="headers" :items="data" height="33vh" fixed-header />
However, what if we don’t want a fixed-height page subarea with a scrollbar? …
Vuetify.js is a Material Design component framework that allows customizing colors easily via themes. However, one color that is missing in the theme config is the background color. In this article we will fix that via CSS variables!
TL;DR — go straight to the final code on Codesandbox:
As described in the official Vuetify.js documentation, it’s possible to choose between a light and dark theme and set the basic colors in the nuxt.config.js file vuetify section: