What is the best way to incorporate v-divider components in between each v-list-item?

I'm attempting to create multiple v-dividers based on the number of answers I have, so that there is a divider for each answer (4). Following an example from the official documentation, I'm trying something like this but I seem to be stuck. Could someone please point out where I am going wrong? https://i.sstatic.net/zftiC.png

Below is the code snippet:

<template>
  <div class="dark2">
    <v-card max-width="600" class="mx-auto">
      <v-toolbar extended class="mt-10" color="light-blue" dark>
        <v-toolbar-title class="flex text-center">
          <h2 class="text-center mt-10">Quiz Dark 2</h2>
        </v-toolbar-title>
      </v-toolbar>

      <v-progress-linear :value="progress"></v-progress-linear>

      <v-list subheader two-line v-for="(element, index) in questions.slice(a,b)" :key="index" v-show="quiz">
        <h1 class="text-center my-4">Question {{ b }}/{{ questions.length }}</h1>
        <v-list-item class="d-flex justify-center text-center">{{ element.question }}</v-list-item>
        <v-divider class="mt-10"></v-divider>

        <v-list-item-group active-class="pink--text">
          <v-list-item class="d-flex justify-center my-2" v-for="(item, index) in element.suggestions" :key="index">
            {{ item.suggestion }}
          </v-list-item>
          <v-divider v-if="index < questions.length - 1"
                     :key="index"></v-divider>
        </v-list-item-group>
      </v-list>

    </v-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      questions: [
        {
          question: 'What does Michael Kahnwald leave for his son Jonas before hanging himself?',
          suggestions: [
            {suggestion: 'A book'},
            {suggestion: 'A letter'},
            {suggestion: 'A futuristic torch'},
            {suggestion: 'A Geiger counter'}
          ]
        }
      ],
      a: 0,
      b: 1,
      select: false,
      score: 0,
      quiz: true,
      score_show: false,
      next: false,
      progress: 0
    }
  }
}
</script>

Answer №1

In the examples provided by Vuetify official documentation Lists Component / Action stack, it is recommended to have a template tag inside the v-list-item-group tag. Here's an example:

  <v-list-item-group active-class="pink--text">
    <template v-for="(item, index) in element.suggestions">
      <v-list-item class="d-flex justify-center my-2" :key="index">
        {{ item.suggestion }}
      </v-list-item>
      <v-divider
          v-if="index < element.suggestions.length - 1"
          :key="`${index}-divider`"
      ></v-divider>
    </template>
  </v-list-item-group>

The key difference is placing the template inside v-list-item-group and then including v-divider next to v-list-item within the custom template.

I hope this information is helpful for your coding endeavors.

Answer №2

Another approach would be to display a divider only if the index is not equal to 0 v-show="index !== 0"

<v-list-item-group active-class="pink--text">
 <template v-for="(item, index) in element.suggestions">
  <v-divider v-show="index !== 0"></v-divider>
  <v-list-item class="d-flex justify-center my-2" :key="index">
    {{ item.suggestion }}
  </v-list-item>
 </template>
</v-list-item-group>

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

Issue with Laravel Nova's Tool.vue: Arrow functions are not functioning properly in computed properties

I am facing an issue with a computed property that is not functioning correctly. After referring to the Vue 2.x documentation, here is the code I have: <template> <div> <button :disabled="isDisabled">Import configurator data ...

"When working with Vue projects, an error may occur stating "Parsing error: No babel config file detected" if the IDE is not opened at

Encountered an issue in VS Code with a Vue project, where if the project is not opened at the root directory, babel.config.js fails to load causing confusion for the IDE. https://i.sstatic.net/pupVh.png All my files display an error on the initial charact ...

Tips for obtaining results from a File Reader

I am currently facing an issue with an onchange event in my HTML. The event is intended to retrieve an image from the user, convert it to a data URL, and then send it over socket.io to store in the database. However, I am struggling to figure out how to ac ...

An elementary React project facing compilation issues

I'm currently exploring react hooks, but I encountered an error with the useReducer hook. The console displays the following error message: "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happe ...

In TypeScript, make sure to verify the type of an object to avoid any potential compilation errors stemming

Here is the code snippet: export default class App { el: HTMLElement; constructor(el: string | HTMLElement) { if (typeof el === "string") { this.el = document.getElementById(el); } if (typeof el === typeof this.el) { t ...

What is the correct way to incorporate a button into a fullcalendar?

element, I am currently utilizing the full calendar and implementing the following function: calendar: function(data, address){ var self = this; console.info(data); $('#calendar').fullCalendar({ height: 500, events: ...

How can I ensure that my script reruns when the window is resized?

Clearly, the question is quite straightforward... I have a script that is drawing graphics across the window. Currently, when I resize the window (e.g., make it full screen), the script only responds to the original size of the window. It should refresh a ...

Plugin initialization cannot occur as the $scope DOM elements are still dynamic and not ready

As I venture into the realm of AngularJS, this project marks my first deep dive into building something substantial, despite having only tinkered with a few tutorials and demos. Bear with me if I struggle to articulate what may be a straightforward questio ...

Error 404: Unable to locate webpack bundle.js

As I dive into learning about Webpack configuration, I keep encountering errors in my console. It appears that my webpack app.bundle.js file is not being found. The page successfully loads with the content of my HTML file displaying, but the app.bundle.js ...

Is it possible for me to create a hyperlink that directs to a javascript function?

Here is the code I am currently using: <input class="button" type="button" value="Mark" onClick="doCheck('mark');" \> However, I would like to replace the button with a hyperlink using the <a> tag. Is it possible to achieve ...

Utilizing Observables in NestJS: Exploring SSE and EventEmitter

I am working on a project where I need to display an event that occurs in the backend on the frontend. Since it is a one-way communication, I have decided to use SSE (Server Sent Events) in nestjs to push the event to the frontend. The setup, as per the do ...

Transmit information to a Django UpdateAPIView using Axios

Currently, I am including the Email in the body of an Axios patch request. const userData = await this.$axios.patch(`/user/${id}/update/`, { email: value }) This data is being sent to the specified API View within Django Rest Framework. ...

javascript display an alert when the page is loaded

My customer wants to display an alert upon visiting a website. The problem is, alerts pause the page loading until the user clicks "Ok," and the client needs the page to continue loading in the background while the alert is visible. We could create a cus ...

Using JQuery and Javascript to retrieve information from one drop down list based on the selection made in another drop down

I'm currently working on a project that involves 2 drop-down menus. The first menu allows you to select a general model, while the second menu displays specific models based on your selection. http://jsfiddle.net/QskM9/ Here's an example of how ...

Accessing external data in Angular outside of a subscription method for an observable

I am struggling to access data outside of my method using .subscribe This is the Service code that is functioning correctly: getSessionTracker(): Observable<ISessionTracker[]> { return this.http.get(this._url) .map((res: Response) => ...

Activate Mixitup Filters Automatically When Page Loads

I have integrated the Mixitup utility from into my ExpressionEngine website. The purpose of this integration is to filter a listing of real estate properties by region, features, and other criteria. My goal is to allow users to pass values via URL segmen ...

What is causing Angular to show undefined when using an object?

I'm relatively new to Angular development. I am currently working on a controller that involves validating user input for registration. svs.controller('registrationCtrl', function($scope, validatorService) { $scope.$watch("registrationFor ...

Adjust the width of every column across numerous instances of ag-grid on a single webpage

I am facing an issue with Ag-grid tables on my webpage. I have multiple instances of Ag-grid table in a single page, but when I resize the browser window, the columns do not automatically adjust to the width of the table. We are using only one Ag-grid in ...

Utilizing Data Binding in D3.js

Why is the text "Hello" not appearing five times on the page as expected? index.html <html> <head> <title>Data Binding</title> </head> <body> <h1>D3.js</h1> <script src="https://d3js.o ...

There is a necessary pause needed between carrying out two statements

I am currently working with extjs 4.2 and I have encountered a situation where I am loading the store object in the following manner: var userDetailStore = Ext.create('Ext.data.Store', { model: 'Person.DetailsModel', autoLoad: ...