How can I iterate over items using v-for in VueJS?

Currently, I am facing an issue with using v-for to iterate through data containing titles and icons. While looping through the data, I can only obtain one icon at a time. My query is regarding how I can retrieve more than one icon during the loop.

You can view the codepen related to this topic here: https://codepen.io/anon/pen/MMaGOZ?&editable=true&editors=101. In this specific example, I wish to include multiple icons such as a search icon in addition to the dashboard icon.


  <div id="app">
 <v-app id="inspire">
   <v-navigation-drawer
    class="blue lighten-3"
    dark
    permanent
   >
     <v-list>
       <v-list-tile
        v-for="item in items"
        :key="item.title"
        @click=""
       >
      <v-list-tile-action>
        <v-icon>{{ item.icon }}</v-icon>
      </v-list-tile-action>

      <v-list-tile-content>
        <v-list-tile-title>{{ item.title }}</v-list-tile-title>
      </v-list-tile-content>
    </v-list-tile>
  </v-list>
</v-navigation-drawer>


 new Vue({
  el: '#app',
  data () {
   return {
    items: [
      { title: 'Dashboard', icon: ['dashboard','search'] },
      { title: 'Account', icon: 'account_box' },
      { title: 'Admin', icon: 'gavel' }
    ]
   }
 }
 })

When attempting to use icon: ['dashboard', 'search'], it displays an error message. Could you provide guidance on resolving this issue?

Thank you for your help.

Answer №1

As stated previously, the code { icon: 'dashboard', 'search' } is invalid and it would be better to utilize an array structure, such as:

items: [
  { title: 'Dashboard', icon: ['dashboard','search'] },
  { title: 'Account', icon: ['account_box'] },
  { title: 'Admin', icon: ['gavel'] }
]

All instances of the icon property have been converted into arrays for consistency and ease of use.

When rendering your template, you can loop through the icons using another v-for

<v-list-tile-action>
  <v-icon v-for="icon in item.icon" :key="icon">{{ icon }}</v-icon>
</v-list-tile-action>

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

Unraveling the mysteries of JQuery AJAX POST and Serialization techniques!

I am struggling to implement an AJAX request using JQuery to validate and submit a form, extract its values, and assign them to variables for further use. Unfortunately, I lack a clear understanding of AJAX functionality as well as how serializing works. ...

AngularJS, sort through "afoo" excluding "foo"

I am attempting to implement a filter within an ng-repeat Main.HTML <table> <tr ng-repeat="param in MyParam | filter: UnrequestValue"> <td>{{param.Label}}</td> </tr> </table> Main.js MyParam: ...

ng-init assign value to a new object

<!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="myCtrl2" ng-init="person = new Person('Al ...

Select a Date: Input for Date Selection

Is it possible to restrict the selection of certain days using HTML date input validation? Some booking websites have a feature where an interactive calendar only allows users to select specific dates for events, while others are greyed out and cannot be c ...

Combining various FormGroup types into a single object type in Angular 5

I am currently utilizing the mat-stepper feature from the Angular Material design library. Within my application, I am using 3 separate FormGroups to gather information and send it to a database using the httpClient method. To achieve this, I have defined ...

Utilize JavaScript Datepicker within the RStudio Environment

Can anyone help me figure out how to add a javascript datepicker to my Shiny app? I'm not sure how to import and execute the code in R. Here is where I found the source code: http://jqueryui.com/datepicker/ I'd prefer to integrate this code into ...

Generating computations within a currently active session

I am currently in the process of developing a shopping application using AngularJS, PHP, a webservice, and various HTML/CSS and XML elements. At the moment, I am focusing on implementing the cart session functionality and have encountered difficulties whe ...

Awaiting fulfillment - Promise remains pending as loop executes queries

I have a scenario where I receive an array containing multiple data elements and need to perform a query for each element in the array. However, this is resulting in a promise pending response. How can I resolve this issue? What could be causing it? getFa ...

Response from the controller upon choosing a value from the selection dropdown

Scenario: In this scenario, there are two tables in consideration: Firm table : ID (string), Firm(string) Firms table: FirmID(string FK), Name(string) The goal is to select a value from the Firm table, pass it to the controller as Firm, and then execut ...

There seems to be an issue with the Redux connect() higher order component not functioning properly when passing an action creator and

Encountering an issue with the Action creator in react-redux when using the mapDispatchToProps function to return an object to pass into the connect HOC. The strange thing is that it works fine when passing the Action creator directly into the connect HOC, ...

Creating custom UV coordinates for tiling textures on ExtrudeGeometry using Three.js

I'm attempting to generate a textured surface along a path in three.js, aiming for a tiling/repeating effect similar to what can be achieved in Blender. Creating individual faces manually and applying textures works well for simple paths like straight ...

Quickly retrieve the current package version in node.js

My project is running on a node.js environment in the browser, and I have a Makefile that bundles all the code into a single file using browserify and then minifies it with (uglify-js). Instead of using Grunt or another tool, I chose to use Makefile becaus ...

Comparing forwardRef and ComponentPropsWithRef: A comparative analysis

Can someone explain the distinction between forwardRef and ComponentPropsWithRef when it comes to adding a ref to my custom function component? const MyComponent = (ref) => { return <div ref={ref}>Some text</div> } I attempted to utilize C ...

Text generated dynamically for buttons

I need help with updating the text on dynamically generated buttons. I tried a method below, but it's not working. $(document).on('click', '.class', function(e){ var thisbut = this.id; $.post('my.php',{ val: val1 ...

Transferring information from Django function to Javascript without the need for refreshing the page

I am currently working with a Django function. @csrf_exempt def postdata(request): r = requests.post(url ,headers=headers, auth=auth, data=json.dumps(data)) return HttpResponse(r) My goal is to pass the variable 'r', which contains a di ...

Create a basic chart using JavaScript

I am looking to replicate a specific chart using JavaScript. The red point in the chart is variable. So far, I have attempted to create it using the flot library: var d3 = [[7,7]]; $.plot("#placeholder", [{ data: d3, points: { show: true } }], { ...

Showing chosen checkbox information using jQuery ajax

When a user enters more than 3 characters into a text box for live search, results are displayed from the database via an AJAX response as checkboxes with names. I want selected checkboxes to display in a separate div below so users can search multiple dat ...

Disparity in React app: Misalignment between debugger and console output

Throughout the years, I've encountered this issue in various ways, and I have finally been able to articulate it. Take a look at the code snippet below: import React, {Component} from "react"; import aFunction from "./Function"; export default class ...

Flick user media cards left or right to uncover the following one

I am currently working on creating a widget that will display user media objects in a horizontal layout using ng-repeat. The goal is to allow users to swipe left or right to reveal the next media card, similar to the image shown below. In the example, you ...

Error: Node.js encountered an EMFILE issue

Trying to open a directory with multiple files, read streams for each, and write the data from all files into one single file. However, encountering Error: EMFILE, open 'chunks/piece96.data'. The ulimit was initially set at 256, then increased t ...