After spending the past 2 hours searching through similar subjects on SO without success, I am turning to you for help.
My goal is to create a scoreboard displaying results in the following format:
- John Doe 100 pts
- John Smith 50 pts
- No Name
- No Name
- No Name
I have an array named scoreBoardArray
containing the necessary data.
data() {
return {
scoreBoardArray: [
{ id: '1', name: 'John Doe', pts: 100 },
{ id: '2', name: 'John Smith', pts: 50 },
],
}
},
I have attempted to loop through this array and display the names and points exactly 5 times, filling in with "No Name" when no record is found.
This is my code (and attempts to solve the issue):
<ul>
<li v-for="item in scoreBoardArray" :key="item.id">
<span v-if="item.id">{{ item.name }} {{ item.pts }}</span>.
<span v-else>No Name</span>
</li>
</ul>
Despite trying to use a computed property and a basic loop like for(let i=0; i<6; i++) {...}
, I haven't been successful in solving the issue.