Vuetify is a popular UI framework for Vue apps.
In this article, we’ll look at how to work with the Vuetify framework.
Outlined Buttons
We can create outlined buttons with the outlined
prop.
For example, we can write:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-btn class="ma-2" outlined color="indigo">Outlined Button</v-btn>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({}),
};
</script>
We can also create an outlined button with an icon inside:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-btn class="ma-2" outlined fab color="teal">
<v-icon>mdi-format-list-bulleted-square</v-icon>
</v-btn>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({}),
};
</script>
Block Button
A block button extends the full width of the screen.
To add one, we can add the block
prop:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-btn block color="secondary" dark>Block Button</v-btn>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({}),
};
</script>
Button Loaders
We can display a loading indicator on the button to notify the user that processing is taking place.
The default behavior is to use a v-progress-circular
component.
This can be customized.
For example, we can write:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-btn
class="ma-2"
:loading="loading"
:disabled="loading"
color="secondary"
@click="loading = true"
>Accept Terms</v-btn>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
loading: false,
}),
};
</script>
Then we can see the loading indicator when we click the button.
loading
is set to true
so that the loading indicator is shown.
The loading
prop is set to the loading state.
Buttons: Floating Action Button
We can add a gloating action button with the fab
prop.
For example, we can write:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-card>
<v-toolbar color="light-blue" light extended>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title class="white--text">App</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
<v-btn icon>
<v-icon>mdi-view-module</v-icon>
</v-btn>
<template v-slot:extension>
<v-btn fab color="cyan accent-2" bottom left absolute @click="dialog = !dialog">
<v-icon>mdi-plus</v-icon>
</v-btn>
</template>
</v-toolbar>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
dialog: false,
}),
};
</script>
We add a v-btn
into the extension
slot so that it shows in the bottom left of the toolbar.
Also, we set the color
prop and add the bottom
and left
props to make it show in the bottom left.
absolute
makes it display with an absolute position.
Display Animation
We can display animation when showing and hiding floating action buttons.
For example, we can write:
<template>
<v-container>
<v-row class="text-center">
<v-col col="12">
<v-card>
<v-toolbar extended>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<template v-slot:extension>
<v-fab-transition>
<v-btn v-show="!hidden" color="pink" fab dark small absolute bottom left>
<v-icon>mdi-plus</v-icon>
</v-btn>
</v-fab-transition>
</template>
</v-toolbar>
<v-card-text style="height: 300px;" class="grey lighten-5 text-center">
<v-btn color="primary" @click="hidden = !hidden">{{ hidden ? 'Show' : 'Hide' }}</v-btn>
</v-card-text>
<v-card-text style="height: 100px; position: relative">
<v-fab-transition>
<v-btn v-show="!hidden" color="pink" dark absolute top right fab>
<v-icon>mdi-plus</v-icon>
</v-btn>
</v-fab-transition>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
hidden: false,
}),
};
</script>
We added the v-fab-transition
prop into the extension
slot to make the floating action button toggle on and off with animation.
The toggling is done with the hidden
prop.
We use the small
prop to make it small.
bottom
and left
position the button icons.
absolute
makes the position absolute.
fab
makes the button a floating action button.
Conclusion
We can display various kinds of buttons with Vuetify.