Vuetify is a popular UI framework for Vue apps.
In this article, we’ll look at how to work with the Vuetify framework.
Horizontal Cards
We can create horizontal cards.
For example, we can write:
<template>
<v-container>
<v-row>
<v-col col="12">
<v-card max-width="400" class="mx-auto">
<v-container>
<v-row dense>
<v-col v-for="(item, i) in items" :key="i" cols="12">
<v-card :color="item.color" dark>
<div class="d-flex flex-no-wrap justify-space-between">
<div>
<v-card-title class="headline" v-text="item.title"></v-card-title>
<v-card-subtitle v-text="item.artist"></v-card-subtitle>
</div>
<v-avatar class="ma-3" size="125" tile>
<v-img :src="item.src"></v-img>
</v-avatar>
</div>
</v-card>
</v-col>
</v-row>
</v-container>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
items: [
{
color: "#1F7087",
src: "http://placekitten.com/200/200",
title: "Cat",
artist: "James Smith",
},
{
color: "#952175",
src: "http://placekitten.com/200/200",
title: "Cat",
artist: "Ellie Jones",
},
],
}),
};
</script>
We create the cards by rendering the v-card
component within the loop.
The v-card
s are in the v-col
.
Inside the card, we have the v-card-title
and v-card-subtitle
to display the title and subtitle.
And we have the v-avatar
on the right side.
Custom Actions
We can add custom actions to our card.
For example, we can write:
<template>
<v-container>
<v-row>
<v-col col="12">
<v-card class="mx-auto" max-width="344">
<v-img src="https://cdn.vuetifyjs.com/images/cards/sunshine.jpg" height="200px"></v-img>
<v-card-title>Sunshine</v-card-title>
<v-card-subtitle>Lorem ipsum</v-card-subtitle>
<v-card-actions>
<v-btn text>Share</v-btn>
<v-btn color="purple" text>Explore</v-btn>
<v-spacer></v-spacer>
<v-btn icon @click="show = !show">
<v-icon>{{ show ? 'mdi-chevron-up' : 'mdi-chevron-down' }}</v-icon>
</v-btn>
</v-card-actions>
<v-expand-transition>
<div v-show="show">
<v-divider></v-divider>
<v-card-text>Lorem ipsum.</v-card-text>
</div>
</v-expand-transition>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
show: false,
}),
};
</script>
We add the v-card-actions
component to display the actions.
Inside it, we have some buttons to let us toggle the bottom pane on and off.
The bottom pane is in the v-expand-transition
component so that we toggle it with the transition.
Twitter Card
We can add a Twitter card by changing styling our card to look like the Twitter UI and add a Twitter icon.
For instance, we can write:
<template>
<v-container>
<v-row>
<v-col col="12">
<v-card class="mx-auto" color="#26c6da" dark max-width="400">
<v-card-title>
<v-icon large left>mdi-twitter</v-icon>
<span class="title font-weight-light">Twitter</span>
</v-card-title>
<v-card-text class="headline font-weight-bold">"hello world."</v-card-text>
<v-card-actions>
<v-list-item class="grow">
<v-list-item-avatar color="grey darken-3">
<v-img
class="elevation-6"
src="https://avataaars.io/?avatarStyle=Transparent&topType=ShortHairShortCurly&accessoriesType=Prescription02&hairColor=Black&facialHairType=Blank&clotheType=Hoodie&clotheColor=White&eyeType=Default&eyebrowType=DefaultNatural&mouthType=Default&skinColor=Light"
></v-img>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>James Smith</v-list-item-title>
</v-list-item-content>
<v-row align="center" justify="end">
<v-icon class="mr-1">mdi-heart</v-icon>
<span class="subheading mr-2">100</span>
<span class="mr-1">·</span>
<v-icon class="mr-1">mdi-share-variant</v-icon>
<span class="subheading">100</span>
</v-row>
</v-list-item>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
show: false,
}),
};
</script>
to add a Twitter-style card.
We have the mdi-twitter
icon.
And the v-card-text
has the tweet.
The v-card-actions
component has the avatar and the name for the user.
And the icon for the likes had retweets are also added.
Conclusion
We can add a Twitter-style and horizontal card with Vuetify.