Implementing interactive functionality to expanding lists in Vuetify.js

Can someone help me figure out how to add an active state for lists in Vuetify? I want the lists to have a primary background color, just like they show in their documentation:

This is my code:

<template>
  <v-navigation-drawer width="300px" :clipped="$vuetify.breakpoint.lgAndUp" app>
    <v-list nav expand>
      <v-list-group
        v-for="(item, i) in items"
        :key="i"
        no-action
        color="primary"
      >
        <template v-slot:activator>
          <v-list-item-content>
            <v-list-item-title>{{ item.title }}</v-list-item-title>
          </v-list-item-content>
        </template>

        <v-list-item
          v-for="(subItem, i) in item.children"
          :key="i"
          @click="$router.push(subItem.path)"
        >
          <v-list-item-content>
            <v-list-item-title v-text="subItem.title"></v-list-item-title>
          </v-list-item-content>
        </v-list-item>
      </v-list-group>
    </v-list>
  </v-navigation-drawer>
</template>

<script>
import SidebarLinks from '@theme/components/SidebarLinks.vue'
import NavLinks from '@theme/components/NavLinks.vue'

export default {
  name: 'Sidebar',

  components: { SidebarLinks, NavLinks },

  props: ['items']
}
</script>


I appreciate any assistance!

Answer №1

The Lists documentation provides detailed information. You can find examples in the Dense section.

item indicates which item from the items list is currently active.

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    item: 1,
    items: [
      { text: 'Real-Time', icon: 'mdi-clock' },
      { text: 'Audience', icon: 'mdi-account' },
      { text: 'Conversions', icon: 'mdi-flag' },
    ],
  }),
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e4841405a6e1b0056">[email protected]</a>/css/materialdesignicons.min.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ceb8bbabbaa7a8b78efce0b6">[email protected]</a>/dist/vuetify.min.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e096958594898699a0d2ce98">[email protected]</a>/dist/vuetify.js"></script>

<div id="app">
  <v-app id="inspire">
    <v-card
      class="mx-auto"
      max-width="300"
      tile
    >
      <v-list dense>
        <v-subheader>REPORTS</v-subheader>
        <v-list-item-group v-model="item" color="primary">
          <v-list-item
            v-for="(item, i) in items"
            :key="i"
          >
            <v-list-item-icon>
              <v-icon v-text="item.icon"></v-icon>
            </v-list-item-icon>
            <v-list-item-content>
              <v-list-item-title v-text="item.text"></v-list-item-title>
            </v-list-item-content>
          </v-list-item>
        </v-list-item-group>
      </v-list>
    </v-card>
  </v-app>
</div>

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

What is the correct way to access an element with spaces in handlebars while working with node.js?

I have an object containing values with spaces in strings. For example: object = { "group of people": [ { (...) } ], "another group of people": [ { (...) } ] } Now, I want to use this object with the handlebars helper block in my view ( ...

What is the best way to configure routes for a Single Page App with Express.js?

I am currently in the process of developing a single page application using Express.js. On my index.html file, I have included a simple form that, upon submission, will send a request to an API, fetch the data, process it, and then display the parsed infor ...

A guide on transferring values from three separate arrays into a designated div using JavaScript

Imagine having 3 div elements and 3 different sets of arrays. The goal is to assign the values from each array into corresponding divs. How can this be achieved? Take a look at my sample divs below: <div id='001'><div id="nr001">< ...

What is the best way to smoothly transition an element into view, then make it disappear seamlessly by fading it

Issue My current code features a <button> that, upon a single click, updates the class of a <div> element to "fade-in" and inserts it into the DOM. This action causes the <div> to visually fade in once it's in the DOM. However, if I ...

Creating a 3D image gallery within a cube using the three.js library

Embarking on my journey to learn JavaScript, I am now delving into the world of WebGL using Three.js. Currently, my goal is to create a rotating cube along the x-axis as a starting point. This cube will feature four different textures - images and text - ...

Using JSON with PHP to send data and receiving the response back with JavaScript

Despite exploring numerous questions and attempting various methods, I have been unable to find a solution that works. Here is my JavaScript file: function sendData() { var jsondata; var j = {"pub_id":"'+pid+'","a_type":"'+a_t&ap ...

Vue main component fails to detect emitted events from child component

I am working on a website that will showcase multiple cards which expand when selected. Here is the code for the card component: <template> <v-card class="mx-auto" max-width="90%" min-height="6 ...

How do I use jQuery to remove a dynamically added class from the page's header?

When using an inline editor to modify css classes, I encounter the need to remove and then re-add a class definition after making changes. Additionally, users have the option to delete elements, so it's important that the definition is also deleted. ...

Express.js automatically sets timeouts for requests to static files

I've been facing this issue for several weeks now - after launching, Express functions properly for a few hours and then suddenly stops serving static files. The situation is as follows: GET / 304 153ms GET /js/bootstrap.min.js 200 120000ms GET /img/ ...

Can you show me how to bind this to a function in events using vue methods?

methods:{ setSwiper() { const test = new something; test.customEvent('changeEvent', this.handleChange); }, handleChange(){ console.log(this)// vue instance } } Within the method handleChange(), I aim to re ...

What is the process for converting and transferring the date in Google Apps Script to generate a new event in Google Calendar?

To create an event in GAS, follow this link: https://developers.google.com/apps-script/reference/calendar/calendar#createEvent(String,Date,Date,Object) var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing', new Date(& ...

Mapping an object in a table only results in the final value being displayed

I am facing an issue with my data object containing an array of data that I have mapped inside a table. The problem arises when I try to retrieve the id value of any item in the table's rows using console.log(). It always returns the id of the last it ...

Stop the Decimal in MUI TextField

Having trouble creating a customized Currency Input? You may be experiencing an issue where the textfield prevents the input of decimals. Take a look at the code below for possible solutions. main.ts const [_val, setVal] = React.useState(""); const h ...

What are some ways to improve this?

This specific code snippet is a crucial component of a weather widget designed for iPhone devices. While the current implementation is functional, I am seeking advice on how to optimize it in order to avoid duplicating the fail function. Any insights or ...

Horizontally position the main word from the D3-WordCloud in the center

I am working on a WordCloud project and have utilized code from Jason Davies D3-JavaScript-WordCloud Example, which can be found at this link. The majority of the code I have used is from a helpful tutorial in German by Lars Ebert, available at this URL. ...

Setting values and options in Material UI AutoComplete and then assigning the selected value to an object when onChange event occurs - how can it be

I am working on a project where I have a brand object with the field cat_id. When the page loads, categories are loaded into an autocomplete select. My goal now is to set the value of category id as the value for a category option in the autocomplete, an ...

Difficulty encountered when choosing and interacting with website button with the utilization of Python 3.5.1 and Selenium 2.53.2

I am currently utilizing a Macbook Air that runs on OS X El Capitan. My tool of choice is Python IDLE, and I am attempting to target and interact with the button located on the webpage below: <div class="search-form-actions"> <button class="btn ...

Displaying data from alternate indices in two separate columns with the use of v-for

My goal is to display the even indexes of the array myArray in a unique way: myArray: [{'label': 'hasan', 'value': 'hosein'}, {'label': '1', 'value': '2'}, ...

Securing your Socket.IO connection with an httpOnly cookie verification

Hello there, I have a query that's been on my mind. In my setup, I'm using NestJS for the backend and VueJS for the frontend. My goal is to update the frontend when the backend finishes a lengthy operation. To achieve this, I believe utilizing so ...

Executing a function when a user chooses to exit a webpage using the @HostListener('window:beforeunload') method

Utilizing @HostListener('window:beforeunload') allows me to detect when a user navigates away from the page, prompting a dialog window to open. I wish for an event to be triggered or a method to be executed if the user chooses to leave the page. ...