What is the best way to showcase several cards containing data retrieved in Vue?

I have a component called Beers and another component called BeerDetailList. In the second component, I'm using a Bootstrap card to display image, title, etc. My issue is that I want to display these cards in multiple rows and columns. I've tried a few different approaches but haven't been successful. Can someone please advise me on how to achieve this?

Beers

<template>
  <div>
    <div v-bind:key="beer.id" v-for="beer in beers">
      <BeerDetailsList v-bind:beer="beer" />
    </div>
  </div>
</template>
<script>
import BeerDetailsList from "./BeerDetailsList";
export default {
  components: { BeerDetailsList },
  name: "Beers",
  props: ["beers"],
};
</script>
<style scoped></style>

Beer Details List

<template>
  <div class="container">
    <b-card-group deck>
      <b-card
        :title="beer.name"
        :img-src="beer.image_url"
        :alt="beer.name"
        img-top
        tag="article"
        style="max-width: 20rem ;"
        class="mb-2"
      >
        <b-card-text>
          {{ beer.tagline }}
        </b-card-text>

        <b-button href="#" variant="primary">View Beer details</b-button>
      </b-card>
    </b-card-group>
  </div>
</template>
<script>
export default {
  name: "BeerDetailsList",
  props: ["beer"],
};
</script>
<style scoped></style>

Answer №1

To ensure that each row contains at most 4 cards, place your for loop within the b-card-group component. Next, include another for loop within the b-card component to display 4 cards for each card group.

You do not require a second component. See example code below:

<template>
  <div class="container">
        <b-card-group deck v-for="i in Math.ceil(beers.length/4)" :key="i">
          <b-card
            v-bind:key="beer.id"
            v-for="beer in beers.slice((i-1)*4, (i-1)*4 +  4)"
            :title="beer.name"
            :img-src="beer.image_url"
            :alt="beer.name"
            img-top
            style="max-width: 20rem ;"
            class="mb-2"
          >
            <b-card-text>
              {{ beer.tagline }}
            </b-card-text>
            <b-button href="#" variant="primary">View Beer details</b-button>
            
          </b-card>
        </b-card-group>
      </div>
</template>
<script>
export default {
  name: "Beers",
  props: ["beers"],
};
</script>
<style scoped></style>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Utilizing images within an iframe: A step-by-step guide

I'm trying to integrate an iframe into a phone image with a transparent background. However, I am unsure how to effectively mask the iframe so that it only appears within the boundaries of the phone image. .phone { display: block; position: r ...

Is there a way to occupy the extra space while working with an inline unordered list?

Using this unique CSS code, I've managed to give my unordered lists a touch of elegance: ul, li { padding: 0px; margin-left: 0px; margin-bottom: 0px; display: inline; } li { border: solid 1px #333333; margin-right: 5px; padding: 2p ...

Switch between various components using multiple buttons in Next.js

I am in the process of creating a component that will display different components depending on which button the user selects. Here are the available “pages”: ` const navigation = [ { name: "EOQ", return: "<EOQgraph />" }, { nam ...

Is there a way I can appropriately display an image in a specific size box?

Check out the code snippet I wrote below: import React from 'react' function OurCourse() { return ( <div className='w-full '> <div className='w-full h-[390px]' style={{ backgroundImage:&apos ...

Adding a gradient to enhance an SVG chart

Hey there! I'm currently experimenting with Plotly to create some awesome charts, and I've been trying to figure out how to give my area-charts a gradient instead of the usual fill with opacity. This is how I typically build my graph: Plotly.ne ...

Unable to access Vue.js cookies: they are not defined

I integrated vue-cookies into my project successfully. In the main.js file, I added the following code: createApp(App) .use(store) .use(router, axios, VueCookies) The script section in App.vue file looks like this: <script> import Navbar fr ...

Uninstalling Vue.js from a Rails application using webpack

After using the command line to install Vue.js, I'm now looking to uninstall it. Is there a way to revert the installation process? bundle exec rails webpacker:install:vue Any guidance on removing Vue.js would be greatly appreciated. ...

Creating a stylish CSS shadow effect for a collection of elements

In my Ionic2 project, I have an <ion-list> consisting of various items. Currently, these items are plain, but I desire to add some styling such that each item in the list displays a subtle shadow effect, similar to the one shown in the first image of ...

Vue is capable of both catching and managing emitted events originating from elements housed within slots

In my setup, I have a Parent component, Child component, and Child-of-child component. The Child component has 2 named slots, while the Child-of-child component has 1 slot. As a result, the template looks something like this: Components Structure <par ...

Refreshing a value in the view at regular intervals using a filter in Vue

Trying to create a countdown timer with vue, but the view is not updating. Here are my app.js and index.html: var nowDate = new Date; var nextNewYearsEve = new Date(nowDate.getFullYear(), 11, 31, 23, 59, 59, 59); var timeLeftToNewYearsEve = nextNewYears ...

IntelliJ does not support the use of newlines within Vue.js component templates

While working with Vue.js in IntelliJ IDEA, I encountered a small problem related to defining component templates. The issue is that IntelliJ seems to struggle when the template spans more than one line and attempts to concatenate them together. For examp ...

Add a captivating backdrop to a div element

So I have this unique HTML element that showcases a large headline with two decorative lines on either side, extending to the full width of the element. However, I now have a requirement to display some text as a background behind this element. The issue ...

Enhance your WooCommerce shopping experience by incorporating a variety of personalized checkout fields organized into two distinct

I have implemented custom code to create unique checkout fields based on the number of products in a customer's cart. Each product requires 4 customized checkout fields, displayed in two columns side by side. The expected result is as follows: co ...

``Incorporating best practices: Setting the height of the parent container equal to the height of

When designing a container, is it considered beneficial to assign each child within the container its own height property, even if the parent container has already been allocated a specific height? If not, are there alternate methods available for transfer ...

Steps to insert a Drop-Down Sub-Menu

I'm just about finished with my navigation panel. Any tips on how to add a sub-menu? I currently have one in the Product page. Below is the HTML code containing the sub-menus: <nav> <ul> <li><a href="">HOME</a>&l ...

The gap separating the three columns in the DIVs structure

Here is an example that I need The images are being loaded from a MySQL while loop, and I want the spacing between them to be such that the left column and right column touch each side with the middle image centered. Just like in the picture :D This is m ...

I can't seem to shake off this constant error. Uncaught TypeError: Unable to access property 'classList' of null

I am facing an issue with the "Contact Me" tab as it does not display its content when clicked. Here is the code snippet: <body> <ul class="tabs"> <li data-tab-target="#home" class="active tab">Home< ...

Vue.js - Capturing a scroll event within a vuetify v-dialog component

Currently, I am working on a JavaScript project that involves implementing a 'scroll-to-top' button within a Vuetify v-dialog component. The button should only appear after the user has scrolled down by 20px along the y-axis. Within the v-dialog, ...

Error: Unable to locate module 'next/font/google/target.css'

After setting up Next.js version 14.0.1 on Node.Js v20.9.0 and Ubuntu 20.04, I encountered an error right from the start. Failed to compile /var/www/html/C#/nextApp/app/layout.js Module not found: Can't resolve 'next/font/google/target.css?{&quo ...

I would like to style the input checkbox using CSS

Is there a way to style input checkboxes with CSS that will work on all browsers (Chrome, Firefox, IE 6, 7, and 8)? If jQuery is the only solution, please let me know. It needs to be compatible with all browsers. Can anyone provide guidance on how to ach ...