Search code examples
javascriptvue.jsvuetify.jsv-for

How to list the items correctly with v-for?


Can anyone help me with this? https://codepen.io/iTaurus85/pen/aRNWdy I can't make PriceItems.text.content appear in v-list-tile-title using v-for. I want to have something like: Testing plan: Full access, -, -, -. Basic plan: Full access, Support, Chat, -. etc. according to PriceItems.text

<div id="app">
  <v-app id="inspire">
   <v-flex xs4 v-for="item in PriceItems" :key="item.title" :class="item.class" >
     <h3 class="price__block-title">{{item.title}}</h3>
     <h5 class="price__block-subtitle">{{item.subTitle}}</h5>
     <v-list dense class="price__block-list">
       <v-list-tile class="price__block-item">
         <v-list-tile-content>
           <v-list-tile-title class="text-xs-center" >
             {{item.text.content}}
           </v-list-tile-title>
         </v-list-tile-content>
       </v-list-tile>
       <v-divider></v-divider>
     </v-list>
   </v-flex>
  </v-app>
</div>

.price__block{
  display: flex;
  align-items: center;
  flex-direction: column;
  background-color: #00a1c7;
  margin: 5px;
}

.v-list.price__block-list {
  background: transparent;
}

new Vue({
  el: '#app',
  data: function() {
    return {
       PriceItems: [
      {class:'price__block price__block-testing',title:'Testing',subTitle:'1 day',
      text:[
        {content:'Full access'},
        {content:' - '},
        {content:' - '},
        {content:' - '}
        ]},
      {class:'price__block price__block-testing',title:'Basic',subTitle:'7 days', 
       text:[
        {content:'Full access'},
        {content:'Support'},
        {content:'Chat'},
        {content:'-'}
        ]},
      {class:'price__block price__block-testing',title:'Standart',subTitle:'30 days', 
       text:[
        {content:'Full access'},
        {content:'Support'},
        {content:'Chat'},
        {content:'Call'}
        ]},
      {class:'price__block price__block-testing',title:'Premium',subTitle:'120 days', 
       text:[
        {content:'Full access'},
        {content:'Support'},
        {content:'Call'},
        {content:'Chat'}
        ]},
    ]

    }
  }
})

Solution

  • Your child content is an array, so you need iterator for that too, just like you did for priceitems v-for="item in PriceItems"

     <v-list-tile-title class="text-xs-center" v-for="itemContent in item.text">
         {{itemContent.content}}
      </v-list-tile-title>
    

    Demo