I ran into a problem that seems to be common, but I can overcome it.
I have an API query that returns a list of objects.
I want to display my page as a grid of cards filled with content.
I want the grid to have 5 columns and the number of rows will adapt to the number of elements in the list.
I can figure out how to implement it.
For example: I have a query that returns
items[ {"id":1,"title":"title1,"description":"description1"} {"id":2,"title":"title2,"description":"description2"} {"id":3,"title":"title3,"description":"description3"} {"id":4,"title":"title4,"description":"description4"} {"id":5,"title":"title5,"description":"description5"} {"id":6,"title":"title6,"description":"description6"} {"id":7,"title":"title7,"description":"description7"} ]
My grid consists of 7 elements, systematically with 5 columns and adaptive rows, for example:
If my query returns for example 14 elements, the layout should be adjusted to look like this:
The closest code I can get is.
<v-container class="mt-2"> <h1>Top Rated views</h1> <v-row v-for="n in gridDivider" :key="n" class="n === 1 ? 'mb-6' : ''"> <v-col v-for="(item,index) in Items" :key="index"> <v-card class="mx-auto" max-width="300"> <v-img class="white--text align-end" height="200px" src="item.avatar" > <v-card-title>anything as text</v-card-title> </v-img> <v-card-subtitle class="pb-0"> Number 10 </v-card-subtitle> <v-card-text class="text--primary"> <div>Whitehaven Beach</div> <div>Whitsunday Island, Whitsunday Islands</div> </v-card-text> </v-card> </v-col> </v-row> </v-container>
thanks for your help
P粉1436404962024-01-30 00:16:19
This can be done if you change the v-row
and v-col
declarations like this:
...
And use CSS Grid Layout
.five-cols { display: grid; grid-template-columns: repeat(5, 1fr); }
ExampleCodePen