Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

v-for looping through nested arrays

In a listed element I’m trying to implement a v-for loop which should iterate the items in the script section.

The HTML code looks like this:

<li
   v-for="item in icludedItems.basicPackage"
   class="flex items-center space-x-3">
   <!-- Icon -->
   <IconsCheck />
   <span>{{ item.basicPackage }}</span>
 </li>

Script sections looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

data() {
    return {
      icludedItems: [
        {
          freePackage: [
            this.$t('pricing.packages.free.includedUsers'),
            this.$t('pricing.packages.free.includedModules'),
            this.$t('pricing.packages.free.includedLocations'),
            this.$t('pricing.packages.free.includedProviders'),
          ],
          basicPackage: [
            this.$t('pricing.packages.basic.includedUsers'),
            this.$t('pricing.packages.basic.includedModules'),
            this.$t('pricing.packages.basic.includedLocations'),
            this.$t('pricing.packages.basic.includedProviders'),
          ],
          advancedPackage: [
            this.$t('pricing.packages.advanced.includedUsers'),
            this.$t('pricing.packages.advanced.includedModules'),
            this.$t('pricing.packages.advanced.includedLocations'),
            this.$t('pricing.packages.advanced.includedProviders'),
          ],
          premiumPackage: [
            this.$t('pricing.packages.premium.includedUsers'),
            this.$t('pricing.packages.premium.includedModules'),
            this.$t('pricing.packages.premium.includedLocations'),
            this.$t('pricing.packages.premium.includedProviders'),
          ],
        },
      ],
    };
  },

However, with this approach no content will be displayed, but also no error.

If I’m removing the nested arrays from includedItems it works as expected.

Anyone a idea what I’m doing wrong? Thanks. 🙂

>Solution :

Try like following snippet. (basicPackage is property from the first object in icludedItems array)

const app = Vue.createApp({
  data() {
    return {
      icludedItems: [
        {
          freePackage: [
            1,2,3,4
          ],
          basicPackage: [
            5,6,7,8
          ],
          advancedPackage: [
            9,10,11,12
          ],
          premiumPackage: [
            13,14,15,16
          ],
        },
      ],
    };
  },
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
  <ul>
    <li v-for="item in icludedItems[0].basicPackage">
      <span>{{ item }}</span>
    </li>
  </ul>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading