What is the process for obtaining a custom slot in a v-data-iterator?

How can I customize the slot in v-data-iterator to change the color and content of certain sections?

Desired Customization: https://i.sstatic.net/bqdfL.jpg

This is what I have tried so far:


        <!-- Custom slot for Calories -->
        <template v-slot:item="calories">
          <v-list-item>
            <v-list-item-content :class="{ 'blue--text': sortBy === key }">
              <!-- Custom value here (green color) -->
              <span style="color: green;">Calories:</span>
            </v-list-item-content>
            <v-list-item-content class="align-end" :class="{ 'blue--text': sortBy === key }">
              <!-- Custom value here (+ kcal) -->
              {{ item.calories }} kcal
            </v-list-item-content>
          </v-list-item>
        </template>
    

What should be the correct "v-slot:" attribute value for the Calories section? Is there an alternative way to customize specific sections?

HTML code:


        <div id="app">
          <v-app id="inspire">
            <v-container fluid>
              <v-data-iterator
                :items="items"
                :items-per-page.sync="itemsPerPage"
                :page.sync="page"
                :search="search"
                :sort-by="sortBy.toLowerCase()"
                :sort-desc="sortDesc"
                hide-default-footer>
                ...
            </v-app> 
        </div>
    

JS code:


        new Vue({
          el: '#app',
        ...
        items:[
            // List of food items with their nutritional values
           ]
        })
    

Full demo code: CodePen Demo

Answer №1

It's not possible to use the v-slot for this specific task.

The data you need is located within v-list-item-content, which is not part of the general v-data-iterator. Unfortunately, v-list-item-content only has a default slot.

However, you can work around this issue by following these steps:

...
<v-list dense>
  <v-list-item
    v-for="(key, index) in filteredKeys"
    :key="index"
  >
    <v-list-item-content :class="{ 'blue--text': sortBy === key }">
      <span v-if="key === 'Calories'" style="color: green">
      {{ key }}:
      </span>
      <span v-else>
      {{ key }}:
      </span>
    </v-list-item-content>
    <v-list-item-content
      class="align-end"
      :class="{ 'blue--text': sortBy === key }"
    >
      <span v-if="key === 'Calories'">
        {{ item[key.toLowerCase()] + ' kcal' }}
      </span>
      <span v-else>
        {{ item[key.toLowerCase()] }}
      </span>
    </v-list-item-content>
  </v-list-item>
</v-list>
...

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

Executing Backbone.history.start() prevents the back button from navigating away from the current page

I've encountered this issue in multiple apps, leading me to question if there's an error in my handling of Backbone history. The scenario is as follows... There are two pages: index.html app.html The index page is a standard HTML page with a l ...

Why isn't my JavaScript AJAX PHP if statement functioning properly?

I have been struggling with this issue for more than two hours now and cannot seem to find a logical solution. When I remove the If statement highlighted by --> this arrow, the alert() function works perfectly fine. It triggers when I simply use if(true ...

MUI Error: Unable to locate module - "Error: Unable to resolve 'moment' module"

Encountering numerous errors when attempting to utilize the date-picker feature from mui-x. Issue: Module not found - Error: Can't resolve 'moment' Problem locating '@mui/x-date-pickers/LocalizationProvider' Error: Module not fou ...

How to implement mouse hover functionality in C# using Selenium?

When attempting to mouse hover on a menu with multiple sub-menus, I encountered an issue where the suggested actions caused other menus to overlap and hide the intended element. Below is the recommended code snippet for hovering over the desired element: ...

Is there a feature similar to Google/YouTube Insight called "Interactive PNGs"?

Recently, I have been exploring the YouTube Insight feature and I am intrigued by how their chart PNGs are generated. When you view the statistics for a video, the information is presented in interactive PNG images. These images seem to be entirely compos ...

Can a person select a characteristic like "height" using Javascript?

Is it doable to set a height for an image in CSS, then detect this gradient using JS and double the width based on the height x2.25? Could this be achieved? ...

The D3 path is generating an unexpected output of 0px by 0px, causing the map not to display properly. I am currently unsure how to adjust the projection to

I am currently working on creating a world map using D3. I obtained the JSON file from the following link: https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json Below is the code snippet I'm using: // Defining SVG dimensio ...

Retrieve a comprehensive inventory of all routes within a Vue project and automatically create a sitemap for the website - Vue Project

Imagine I've set up a route like this: import Vue from "vue"; import Router from " vue-router"; import BookRoutes from "./routes/book"; Vue.use(Router) const router = new Router({ routes:[ { path ...

Every time I attempt to submit the login form on the Ionic and Angular page, instead of capturing the values of the form group, the page simply refreshes

Struggling with submitting the login form in Ionic and Angular? When attempting to submit, the page reloads instead of capturing the form group values. I am utilizing angular reactive forms and form builder within the ionic framework. Need assistance in id ...

Real-time File Updates Display with Node.js and Express.js

Seeking guidance on whether there is a Node module available to utilize the Express module for displaying real-time updates in the browser using data from a file. I have a regularly updated .csv file and I am looking to showcase these updates instantly on ...

Execute a function upon pressing the enter key

Currently, I am working on coding a webpage with a form that includes one field where users input a set of numbers. After typing in the numbers, they should then press a button labeled 'Run' to execute the code. However, the issue arises when use ...

Having trouble with Angular NgbModal beforeDismiss feature?

My goal is to add a class to the pop up modal before closing it, and then have it wait for a brief period before actually closing. I've been trying to do this using the beforeDismiss feature in the NgbModalOptions options in Angular Bootstrap's d ...

Load and execute a dynamically created script in JavaScript at the same time

I am exploring the option to load and evaluate a script from a third-party synchronously. Here is an example that currently works well: <head> <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfe ...

Unit test: Passing a deeply nested object as a prop to a React component

My functional component looks like this: const ImageScreen = (props: any) => { const images: object[] = []; props.navigation.state.params.images.forEach((image: any) => //some code ); return ( <View style={CommonStyles.normalPage} ...

A method for integrating a Child Component into a UI5 parent application without specifying them in the manifest.json

Seeking advice on loading a Child Component in a UI5 parent app. Currently working on creating a Fiori Launchpad that can dynamically load other apps as Child Components. I have been exploring methods mentioned in an insightful post at However, the imple ...

What is the syntax for implementing a nested for loop in JavaScript within this particular scenario?

var entries = [ { "item": "something", "steps": [{ "node": {"name": "test0"}, "status": {"name": "test"}, "time": {"name": "test"} },{ "node": {"name": "test1"}, ...

The $.post method is malfunctioning

I am experiencing an issue where the onchange function is working properly, but the $.post function is not functioning as expected. Below is the HTML code snippet: <input type="checkbox" id="chk" value="3" onchange="checkradio(this.value)"/> Here ...

Obtaining and Assigning Filter Values in Material Table

Is there a way to programmatically obtain and adjust filter values with material-table? I am looking to enable users to save filter settings as reports and access them whenever necessary. ...

Is there a way to make the directional light illuminate only one half of the sphere in Three js (R3F)?

I'm trying to achieve a lighting effect on a sphere using two directional lights. One light is positioned in front of the sphere to mimic sunlight, while the other is placed towards the back to represent city lights. I'm experimenting with differ ...

Transforming items into an array

Creating a JSON object with the following structure is something I'm trying to accomplish: { "PROMO": { "ID": 1, "NAME": "PROMO ONE", "BUNDLES": { "0": { "BUNDLE": { ...