0

I'm using Vue @2.5.17 and Vuetify @2.33 in a project. I want to create submenu only within the object which contains subLinks array. I tried using docs & many tutorials but was unable to achieve this. How could i achieve this?

Template

<v-navigation-drawer app dark class="primary" v-model="drawer">
    <v-list-item>
        <v-list-item-content>
            <v-list-item-title class="title">
                <span class="font-weight-bold">Al-Mehmood</span>
            </v-list-item-title>
            <v-list-item-subtitle>Transport Company</v-list-item-subtitle>
        </v-list-item-content>
    </v-list-item>

    <v-divider></v-divider>

    <v-list dense>
        <v-list-item link v-for="navLink in navLinks" :key="navLink.text" :to="navLink.route">
            <v-list-item-icon>
                <v-icon>{{ navLink.icon }}</v-icon>
            </v-list-item-icon>

            <v-list-item-content>
                <v-list-item-title>
                    {{
                    navLink.text
                    }}
                </v-list-item-title>
            </v-list-item-content>
        </v-list-item>
    </v-list>
</v-navigation-drawer>

Script

data() {
    return {
        drawer: true,

        navLinks: [
            { icon: "dashboard", text: "Dashboard", route: "/" },
            { icon: "star", text: "Ratings", route: "/ratings" },
            {
                icon: "people",
                text: "Drivers",
                route: "/drivers",
                subLinks: [
                    { text: "Add Driver", route: "/drivers/add" },
                    { text: "Add Driver", route: "/drivers/add" }
                ]
            },

            {
                icon: "person_outline",
                text: "Manager",
                route: "/managers",
                subLinks: [
                    { text: "Add Manager", route: "/managers/add" },
                    { text: "Managers", route: "/managers" }
                ]
            },
            { icon: "person", text: "Manage Users", route: "/users" }
        ]
    };
}

Any help would highly be appreciated.

0

2 Answers 2

1

Use the list-group...

    <v-navigation-drawer app dark class="primary" v-model="drawer">
        <v-list>
            <v-list-item>
                <v-list-item-content>
                    <v-list-item-title class="title">
                        <span class="font-weight-bold">Al-Mehmood</span>
                    </v-list-item-title>
                    <v-list-item-subtitle>Transport Company</v-list-item-subtitle>
                </v-list-item-content>
            </v-list-item>
            <v-divider></v-divider>
            <v-list-group no-action v-for='navLink in navLinks' :key="navLink.text">
                <v-list-item slot='activator' :to="navLink.route">
                    <v-list-item-icon>
                        <v-icon>{{ navLink.icon }}</v-icon>
                    </v-list-item-icon>
                    <v-list-item-title>{{ navLink.text }}</v-list-item-title>
                </v-list-item>
                <v-list-item v-for='sub in navLink.subLinks' :key="sub.text">
                    <v-list-item-title :to="sub.route">{{ sub.text }}</v-list-item-title>
                </v-list-item>
            </v-list-group>
        </v-list>
    </v-navigation-drawer>

Demo: https://codeply.com/p/hZE2TMlslF

Sign up to request clarification or add additional context in comments.

1 Comment

Your demo is working fine but in my project, when i click themenu item, the item itself disappears.
1

this is the solution, a computed property!

computed: {
  filteredNavLinks() {
    return this.navLinks.filter(
      navLink => navLink.subLinks && navLink.subLinks.length
    );
  }
}

Now you v-for must be updated to use filteredNavLinks

<v-list dense>
    <v-list-item link v-for="navLink in filteredNavLinks" :key="navLink.text" :to="navLink.route">
        <v-list-item-icon>
            <v-icon>{{ navLink.icon }}</v-icon>
        </v-list-item-icon>

        <v-list-item-content>
            <v-list-item-title>
                {{
                navLink.text
                }}
            </v-list-item-title>
        </v-list-item-content>
    </v-list-item>
</v-list>

Try and let me know if it works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.