The easiest way is to use a v-for
. It's in relation to a for-loop
in other programming languages.
The syntax for this code is looking like this:
<div v-for="item in json" :key="item"></div>
Based on what you want to show a single v-for
or a nested v-for
.
NOTICE: I've named your json json
for better understanding.
ONE V-FOR LOOP:
<template>
<div v-for="firstLoop in json" :key="firstLoop">
{{firstLoop}}
</div>
</template>
OUTPUT:
{ "1": [ "15-16", "16-17", "17-18", "18-19" ], "2": [ "15-16", "16-17", "17-18", "18-19" ] }
TWO V-FOR LOOPS:
<template>
<div v-for="firstLoop in json" :key="firstLoop">
<div v-for="secondLoop in firstLoop" :key="secondLoop">
{{secondLoop}}
</div>
</div>
</template>
OUTPUT:
[ "15-16", "16-17", "17-18", "18-19" ]
[ "15-16", "16-17", "17-18", "18-19" ]
THREE V-FOR LOOPS:
<template>
<div v-for="firstLoop in json" :key="firstLoop">
<div v-for="secondLoop in firstLoop" :key="secondLoop">
<div v-for="thirdLoop in secondLoop" :key="thirdLoop">
{{thirdLoop}}
</div>
</div>
</div>
</template>
OUTPUT:
15-16
16-17
17-18
18-19
15-16
16-17
17-18
18-19
For understanding: You are looping over an json or array which you will define, than you set the key (important!). You can see based on OUTPUT
which I've written after every loop how the syntax is working and can try it out for your own.
You can also an index to your v-for
than you have to write it like this:
<div v-for="(item, index) in json" :key="index">
Than you can reference everything on your index
.
Hopefully this answer helps you out!