Vuetify is a popular UI framework for Vue apps.
In this article, we’ll look at how to work with the Vuetify framework.
Expandable Chips
A chip can be combined with the v-menu
to enable a set of actions for a chip.
For example, we can write:
<template>
<v-container>
<v-row>
<v-col col="12">
<v-card max-width="400" class="mx-auto">
<v-row class="px-6 py-3" align="center">
<span class="mr-4">To</span>
<v-menu v-model="menu" bottom right transition="scale-transition" origin="top left">
<template v-slot:activator="{ on }">
<v-chip pill v-on="on">
<v-avatar left>
<v-img src="https://cdn.vuetifyjs.com/images/john.png"></v-img>
</v-avatar>John Leider
</v-chip>
</template>
<v-card width="300">
<v-list dark>
<v-list-item>
<v-list-item-avatar>
<v-img src="https://cdn.vuetifyjs.com/images/john.png"></v-img>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>John Smith</v-list-item-title>
<v-list-item-subtitle>john@smith.com</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon @click="menu = false">
<v-icon>mdi-close-circle</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
</v-list>
<v-list>
<v-list-item @click="() => {}">
<v-list-item-action>
<v-icon>mdi-briefcase</v-icon>
</v-list-item-action>
<v-list-item-subtitle>john@gmail.com</v-list-item-subtitle>
</v-list-item>
</v-list>
</v-card>
</v-menu>
</v-row>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
menu: false,
}),
};
</script>
We have the v-menu
that wraps outside the v-chip
.
The v-chip
has some text and an avatar.
Also, the v-list-item
has the list that we show when we click on the chip.
The v-on="on"
directive lets us toggle the menu since on
includes the click listener.
Also, we have a close circle button to set menu
to false
when we click it.
This way, the menu will close.
Dialogs
The v-dialog
lets us display a dialog.
To use it, we write:
<template>
<v-container>
<v-row>
<v-col col="12">
<v-row justify="center">
<v-btn color="primary" dark @click.stop="dialog = true">Open Dialog</v-btn>
<v-dialog v-model="dialog" max-width="290">
<v-card>
<v-card-title class="headline">Title</v-card-title>
<v-card-text>Lorem ipsum.</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="green darken-1" text @click="dialog = false">Cancel</v-btn>
<v-btn color="green darken-1" text @click="dialog = false">OK</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-row>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
dialog: false,
}),
};
</script>
to create a dialog with the v-dialog
component.
v-model
binds to the dialog
state to control the opening and closing of the dialog.
We also have the v-btn
to set dialog
to false
when we click on the buttons.
The Open Dialog button sets dialog
to true
when we click it so the dialog opens when we click it.
Conclusion
We can make a chip show a menu when we click it.
Also, we can create a dialog box with the v-dialog
component.