What is a way to hide or exclude tabs when there is no content to display for a particular tab in Vue?

I'm new to javascript and Vue, and I'm trying to figure out how to hide tabs that don't contain any information. I want to display only the tabs that do have information. Can someone please help me with this?

I automatically pull images based on naming conventions, and they should display under the correct tab if the file names match. However, not all bundles contain all sizes of images, so I want to show only the tabs that meet the criteria and hide the rest. This is also my first time asking a question here, so if I missed anything, please let me know. Thank you.

<script>

export default {
    name: "Tab",
    data () {
        return {
          currentTab: 0,
          tabs: null,
          tabNames: [
            {title: 'tab one', size: 'one'},
            {title: 'tab two', size: 'two'},
            {title: 'tab three', size: 'three'},
            {title: 'tab four', size: 'four'},
            {title: 'tab five', size: 'five'},
            {title: 'tab 6', size: 'six'},
            {title: 'tab 7', size: 'seven'},
            {title: 'tab 8', size: 'eight'},
            {title: 'tab 9', size: 'nine'},
            {title: 'tab 10', size: 'ten'},
            {title: 'tab 11', size: '11'},
           ],
           show: false
        }
    },
    props: {
        files: {
          type: Array,
          default: () => []
        },
    },
    methods: {
      sizeImg(size) {
        const bundleRE = new RegExp()
      },
    }
}
</script>
<style lang="scss" scoped>       
  .thumbnail {
  display: inline-block;
  max-width: 100%; /* only this one important */
  margin-bottom: 0rem;
  margin-right: 1rem;
  border: 0;
  line-height: 0; }
</style>
<template>
  <div>
    <v-toolbar
      color="#212121"
      dark
      height="80"
      extension-height="110"
      tabs
    >
      <template v-slot:extension >
        <v-tabs
          v-model="tabs"
          color="#212121"
          grow
        >
        <v-tabs-slider color="#a60808"></v-tabs-slider>
          <v-tab 
            v-for="(tab, index) in tabNames"
            :key="index">
            {{ tab.title }} 
          </v-tab>
        </v-tabs>
      </template>
    </v-toolbar>
    <v-tabs-items v-model="tabs">
      <v-tab-item v-for="(tab, index) in tabNames" :key="index">
        <v-card flat>
          <v-container grid-list-md text-xs-center>
            <v-layout row wrap>
              <v-flex xs12>
                <v-card-text><img class="thumbnail" v-for="(i, n) in sizeImg(tab.size)" :key="n" :src='i'></v-card-text>
              </v-flex>
            </v-layout>
          </v-container>
        </v-card>
      </v-tab-item>
    </v-tabs-items>
  </div>
</template>

Answer №1

One way to filter out unwanted tabs is by creating a computed property called parsedTabs. Here's an example:

parsedTabs() {
  return this.tabs.filter(tab => tab.size);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing SSL with Vue CLI for local development: A step-by-step guide

I've been exploring how to enable HTTPS with Vue CLI and have come across a method that involves setting "https: true" under devServer in a vue.config.js file. However, I also understand that I need to obtain a self-signed certificate for this setup. ...

Remove the active class from a list item using History.js

My goal is to add the active class to a link when clicked in my AJAX app, triggering statechange on History.js. I'm struggling with saving the current active link(s) with the state so that the active class is appropriately added or removed when naviga ...

Tips for Angular4: ensuring ngOnDestroy completion before navigation

My task involves managing a list of objects where the user can choose an object to edit using a child component. However, when the user returns to the list component, the child component needs to clean up in the ngOnDestroy method, which includes making a ...

Extract information from a database table for presentation as simple text

I am looking to extract information from each row and display it as plain text on the same page within a paragraph. Here is an example table for reference: <table> <thead> <tr> <th class="a header">A</th ...

Strikeout list on click of a mouse

Is there a way to apply strikethrough formatting to text with just a mouse click? The CSS for lists is beyond the form field margin. I've tried multiple methods without success. No matter how many times I change the code, I can't seem to get it r ...

Vue warning: Issue encountered during rendering - TypeError: Attempting to access the 'id' property of an undefined variable

As I develop my CRUD application using Laravel and VueJS, I encounter an error message when submitting the creation form: [Vue warn]: Error in render: "TypeError: Cannot read property 'id' of undefined" Below is my createUser method: export def ...

Encountering a mysterious error while attempting to access and modify a value stored in a useState hook using the keydown

I've been attempting to create a simple animation on canvas using React.js, but I'm facing an issue with integrating my Keydown function with my useState. It seems that my useState value is not being defined properly, preventing me from changing ...

I'm encountering the error message "Controller not a function, received undefined" even though I have not declared the controller globally

Encountering the same ERROR Argument 'AveragesCtrl' is not a function, got undefined. Despite attempting various solutions found on SO, I am still unable to resolve this issue. Any insights into what might be causing my error? <div > ...

Incorporating JSON data seamlessly into a visually appealing Highcharts pie chart

It seems like I'm facing a minor issue here. Everything was working fine until... $(document).ready(function() { // Original data var data = [{ "name": "Tokyo", "y": 3.0 }, { "name": "NewYork", "y": 2.0 }, { "name": "Berlin", ...

Freezing Columns and Rows for a Spacious Scrollable Table

After extensive effort, I have been diligently striving to create a solution that allows a table's column headers to scroll with the body horizontally and the first column to scroll with the rows vertically. While I've come across solutions that ...

jQuery GetJson fails to execute success function

I'm trying to use this code for an Ajax request to a JSON file: let formData = $("#myform").serialize(); $.getJSON("/files/data.json?" + formData, function(response){ alert(response); } ); However, there are no errors and the alert is n ...

Restrict Recursive GraphQL Schema Query Depth with graphql-sequelize resolver in Node.js using express-graphql

In my code, I have two models called User and Post. My goal is to retrieve User information when querying a post, as well as obtain all of a User's posts when querying a user. These two models are associated in the following manner: User.hasMany(Pos ...

Unveiling Three.js: Exploring the Unique One-Sided Surface

Here is the three.js code: <script type="text/javascript"> init(); animate(); // FUNCTIONS function init() { // SCENE scene = new THREE.Scene(); // CAMERA var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight; var VIEW_A ...

Error: Cannot access 'muiName' property as it is undefined

i am trying to display the elements of an array within a custom card component in a grid layout. However, when the page loads it freezes and the console shows "Uncaught TypeError: Cannot read property 'muiName' of undefined" custom car ...

How can I pass a specific value, rather than the entire array, in a ReactJS dropdown menu?

I am facing a problem where the entire array is being passed as an argument when I call onchange after getting correct values in the dropdown. Instead of only receiving the selected value, e contains the whole array. Here is the code snippet that demonst ...

Issue with Google Charts where the label does not show outside of the bar if the bar is too small

I am encountering an issue with my Google Bar Chart where the bar label is not displaying outside of the bar when it is too large to fit inside. This behavior should be the default, but my charts are not working as expected. The problem can be seen in rows ...

The grid fails to apply remote filtering values when an additional Nested ajax call is incorporated alongside the current HttpProxy configuration

Whenever I click for filter/sort for remote filtering, Forms.asp triggers using a proxy and automatically reloads. Previously, when I used the script below to reload the ExtJS grid with Forms.asp returning new XML with filtered grid data, everything worked ...

Leverage the power of JavaScript validation combined with jQuery

Hello, I'm relatively new to the world of Javascript and jQuery. My goal is to create a suggestion box that opens when a user clicks on a specific button or div element. This box should only be visible to logged-in users. I have some knowledge on how ...

Tips for creating a dynamic menu item that stands out with a highlighted style

I would like to add a colored square to highlight the active menu item. .main-menu ul { padding: 0; margin: 0; text-align: center; } .main-menu li { list-style-type: none; display: inline-block; padding: 40px 0; } .main-menu a { font-fam ...

How come it's not possible to modify the text of this button right when the function kicks off?

When I click a button, it triggers a JavaScript function. The first line of code within the function uses jQuery to change the HTML of the button. However, the button's text does not update in the browser until after the entire function has completed, ...