Here's an Updated Example
To start, avoid combining them in the computed property and instead, try implementing a v-for loop approach like the one below:
This is my personal solution, based on the real API data. By nesting loops and mapping out the data for simplicity, you will achieve something similar to this structure:
[
{
key: 'gta-v',
storeUrls: [
{
key: 'steam',
url: 'http:// ...'
},
{
key: 'riot',
url: 'http:// ...'
}
]
},
{
key: 'fortnite',
storeUrls: [
{
key: 'steam',
url: 'http:// ...'
},
{
key: 'riot',
url: 'http:// ...'
}
]
}
]
This method also allows for a double-loop using v-for in the template, sorting the data by game and iterating through each game's storeUrls for a clean list presentation. This approach emphasizes utilizing actual keys over index values.
<template>
<div class="root">
<div class="game" v-for="game in games" :key="game.key">
<h1>{{ game.key }}</h1>
<a v-for="store in game.storeUrls" :href=“store.url” :key="store.key">
{{store.url}}
</a>
</div>
</div>
</template>
export default {
data() {
return {
myData: null
}
},
computed: {
games() {
if (!this.myData) return [];
return this.myData.results.map(game => {
key: game.slug,
storeUrls: game.stores.map(store => {
return {
key: store.store.slug,
url: store.url_en
}
});
});
}
},
methods: {
getData() {
// Fetch the raw data without any mappings.
this.myData = axios.get('...');
}
}
}