Using Vuetify to incorporate properties into v-list-group v-slot:activator template

Trying to create a menu similar to the expansion lists example in the Vuetify documentation. This menu utilizes the v-list-group and v-slot:activator components. Each child element has a list-item, making it easy to add a Vue Router link. However, the challenge arises when a parent list item (e.g., Dashboard) has no children items. In such cases, I want to add a Vue Router link using the :to directive, but I'm uncertain about how to achieve this since the parent list items use the v-slot:activator template.

I've looked into the v-slot activator on GitHub, but I couldn't find information on how to implement the functionality I require.

Template

    <v-list>
        <v-list-group
            v-for="item in items"
            :key="item.name"
            v-model="item.active"
            :prepend-icon="item.icon"
            :append-icon="item.children ? undefined : ''"
            no-action
        >
            //Need to make this work with :to or @click
            <template v-slot:activator :to="{name: item.route}">
                <v-list-item-content>
                    <v-list-item-title v-text="item.name"></v-list-item-title>
                </v-list-item-content>
            </template>

            <v-list-item
                v-for="childItem in item.children"
                :key="childItem.name"
                :to="{name:childItem.route}"
            >
                <v-list-item-content>
                    <v-list-item-title v-text="childItem.name"></v-list-item-title>
                </v-list-item-content>
            </v-list-item>
        </v-list-group>
    </v-list>

Data

     items: [
                {
                    name: 'Dashboard',
                    route: 'dashboard',
                    active: false,
                    icon: 'mdi-view-dashboard',
                },
                {
                    name: 'Editor',
                    icon: 'mdi-pencil',
                    active: false,
                    children: [
                        {
                            name: 'General',
                            route: 'general',
                        },
                        {
                            name: 'Designs',
                            route: 'designs',

                        },
                        {
                            name: 'Images',
                            route: 'images',
                        },
                    ],
                },
          ];

Update

I found a solution by including a v-list-item within the template when the parent element has a route key. I then used absolute positioning to extend its size to match the parent template. Am I missing a more efficient approach for achieving this?

    <template v-slot:activator>
        <v-list-item v-if="item.route" :to="{name: item.route}" class="item-link"></v-list-item>
        <v-list-item-content>
            <v-list-item-title v-text="item.name"></v-list-item-title>
        </v-list-item-content>
    </template>

Style

 .item-link {
   position: absolute;
   top: 0;
   bottom: 0;
   right: 0;
   left: 0;
 }

Answer №1

If you're still in search of a solution, I faced the same problem and came up with a workaround that utilizes the slot attribute (not the V-SLOT in the template). Remove the template and take a look at the following code snippet:

<v-list-group v-for="(parentCat, parent_id) in item.parent_cat" :key="`${parent_id}parentCat`" :value="openParent==parent_id" append-icon="" active-class="tagActiveIcon" @click="parentCatChanged(parent_id)" :disabled="true">
    <div slot="activator" class="d-flex justify-space-between maximizeWidth" @click="parentCatChanged(parent_id)">
        <div>Par_{{ parentCat.title}}</div>
        <div><v-icon color="primary">mdi-eye</v-icon></div>
    </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

Creating a table and populating its cells with values all within the confines of a single function

This section of code aims to create 3 arrays by extracting values inputted by the user from a popup menu in the HTML file. These values are then utilized to populate the table displayed below. var arrM = new Array; var arrT = new Array; var ar ...

Utilizing variables upon the page being refreshed

Is there a way to retain certain data even when the page is refreshed? I have some values stored in an array and would like to keep them without losing them upon refreshing. ...

I am in need of a efficient loader for a slow-loading page on my website. Any recommendations on where to find one that works

I'm experiencing slow loading times on my website and I'm looking to implement a loader that will hide the page until all elements are fully loaded. I've tested several loaders, but they all seem to briefly display the page before the loader ...

Having difficulties achieving successful API requests in Next.js and Snipcart

I'm currently diving into the world of Snipcart, and I'm encountering some issues connecting to your API. I'm using Next.js and haven't been able to find any solutions on the forum or in the documentation that address my specific proble ...

Spin the content of a div after a button click with the power of jquery and css

Looking to add interactivity to rotate text within a div upon button click using jQuery and CSS. If the user selects Rotate Left, the text will rotate to the left. Alternatively, if the user chooses Rotate Right, the text will rotate to the right. Here&a ...

Issue with dynamic form JavaScript functionality after removing curly braces { } from a select tag in Rails

In my Rails form, there is a gender field defined as follows: <%= f.select :gender, ["Male","Female"],{class: "gender"} %> I also tried adding an onclick event like this: <%= f.select :gender, ["Male","Female"],{class: "gender"},onclick: "categ ...

Switch between viewing outcomes retrieved from a database

I'm fairly new to working with jQuery, PHP and databases, but I have managed to successfully create a database and retrieve data using PHP. When a search term is entered, the retrieved data from the database is displayed on the results page. For exam ...

construct a table utilizing JSON information

If I have data returned from an ajax call that needs to be processed, a table like the following needs to be created: ID NAME Object Type ============================================== 1 SWT-F1-S32-RTR-1 Network Switch 2 ...

What causes my browser fingerprint to consistently remain unchanged?

declare var Fingerprint2: any; @Component({ selector: 'my-app', template: `Hello`, }) export class App { constructor() { new Fingerprint2().get(function(result, components){ console.log(result); // Device fingerprint as a hash va ...

"Adding dots" in a slideshow using HTML, CSS, and JS

I'm currently working on a slideshow that includes navigation dots at the bottom. Although the slideshow is functioning properly, I am encountering an issue where only one dot appears instead of the intended three in a row. Despite my research and att ...

Is it possible to have unique color tags in Material UI Autocomplete?

I'm currently diving into the world of material-ui and encountering some challenges that I could use help with. I am trying to incorporate multiple arrays into the autocomplete menu (e.g., options={top100Films, top100Shows}, but with the correct sy ...

I need to mass upload a collection of resumes stored in a zip file, then extract and display the content of each resume using a combination of HTML

I recently used a service to extract and retrieve the contents of a zip file. I am trying to read the content of the files and integrate them into the scope of my Angular project. Any suggestions would be greatly appreciated. Below is an outline of my func ...

Having trouble shutting down the window using Electron and Socket io

I embarked on a chat application project using NodeJS and Socket.io, everything was running smoothly. However, when I decided to integrate my app into the Electron framework, the chat window opened but I encountered an issue with the close button not func ...

Connecting JSON objects based on unique GUID values generated

I am in search of a method to automate the laborious task of linking multiple JSON objects with random GUIDs. The JSON files are all interconnected: { "name": "some.interesting.name", "description": "helpful desc ...

Is it acceptable to compare a boolean with a string?

In my code, I have a variable called isRefreshed which is initially declared like this: var isRefreshed = ''; Sometimes, in certain scenarios, isRefreshed can be assigned a boolean value, for example: isRefreshed = false; Now, there is an if ...

Yesterday Box: Creating and Launching URL with Today's Date via Javascript Bookmarklet

Is it possible to create a simple bookmarklet that generates a URL with the current date and opens it automatically in the browser? This feature could be useful for creating URLs for prefilled forms or implementing something like yesterbox for web-based e ...

Error encountered upon initializing Node-RED due to the presence of an unexpected token while incorporating the NPM module "file-exists" into the

Currently, I'm in the process of developing an application using Node-RED and I'm looking to incorporate some NPM modules into my project. One particular module from James Thom caught my attention, called node-red-contrib-npm, which automates the ...

Using Vue JS to showcase array data in a dropdown menu with Bootstrap-vue

Currently, I have an array of JSON data structured like this: loggers = [{ "allAvailableLevel": ['WARN', 'DEBUG', 'INFO'], "level": "WARN", "logger": "com.test1", "status": "success" }, { ...

Highlight dates in Vue.js that are overdue using a date filter

Currently, I have a Vue filter set up to display dates in a visually appealing way. However, I am looking to enhance the filter by adding a feature that would highlight dates in red if they are overdue (meaning the date is earlier than the current date). I ...

How can Jquery detect when users click on 'ok' in confirm() pop-up dialogs?

Within my application, I have multiple confirmation dialogues that appear when users attempt to delete certain items. Is there a method to determine if a user has clicked the 'ok' button on any of these dialogues globally so that I can execute a ...