Vuetify is a popular UI framework for Vue apps.
In this article, we’ll look at how to work with the Vuetify framework.
Menus
We can place menus in any component.
For example, we can write:
<template>
<v-row>
<v-col cols="12" sm="6" offset-sm="3">
<v-card height="200px">
<v-card-title class="blue white--text">
<span class="headline">Menu</span>
<v-spacer></v-spacer>
<v-menu bottom left>
<template v-slot:activator="{ on, attrs }">
<v-btn dark icon v-bind="attrs" v-on="on">
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
</template>
<v-list>
<v-list-item v-for="(item, i) in items" :key="i">
<v-list-item-title>{{ item.title }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-card-title>
<v-card-text>Lorem Ipsum</v-card-text>
</v-card>
</v-col>
</v-row>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
items: [
{ title: "Click Me" },
{ title: "Click Me 2" },
{ title: "Click Me 3" },
],
}),
};
</script>
We put our v-menu
in the v-card
component.
Then v-menu
has the bottom
and left
props so that we can place it at the bottom left of the card.
Navigation Drawers
To add a navigation drawer, we can add the v-navigation-drawer
component.
For example, we can write:
<template>
<v-row>
<v-col cols="12">
<v-card class="mx-auto" height="400" width="256">
<v-navigation-drawer class="deep-purple accent-4" dark permanent>
<v-list>
<v-list-item v-for="item in items" :key="item.title" link>
<v-list-item-icon>
<v-icon>{{ item.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ item.title }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
<template v-slot:append>
<div class="pa-2">
<v-btn block>Logout</v-btn>
</div>
</template>
</v-navigation-drawer>
</v-card>
</v-col>
</v-row>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
items: [
{ title: "Click Me" },
{ title: "Click Me 2" },
{ title: "Click Me 3" },
],
}),
};
</script>
We have the v-list
to show a list of items.
This is put inside the v-navigation-drawer
to make it show in the drawer.
Permanent Floating Drawer
We can add a navigation drawer that floats on the page.
For example, we can write:
<template>
<v-row>
<v-col cols="12">
<v-card class="pa-12" color="indigo darken-2" flat>
<v-card elevation="12" width="256">
<v-navigation-drawer floating permanent>
<v-list dense rounded>
<v-list-item v-for="item in items" :key="item.title" link>
<v-list-item-icon>
<v-icon>{{ item.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ item.title }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-navigation-drawer>
</v-card>
</v-card>
</v-col>
</v-row>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
items: [
{ title: "Click Me" },
{ title: "Click Me 2" },
{ title: "Click Me 3" },
],
}),
};
</script>
We have the menu floating on the page with the permanent
and floating
props.
Conclusion
We can add the various kinds of menus with Vuetify.