Here's a sample code that might help you achieve your requirements:
<template>
<v-tab v-for="(category, index) in categories" :key="index" @click="activeCategory = category">
{{ category }}
</v-tab>
<v-tab-item v-for="(category, index) in categories" :key="index" :value="category">
<v-container>
<v-row v-for="(option, optionIndex) in options[index]" :key="optionIndex">
<v-col v-for="(image, imageIndex) in option" :key="imageIndex">
<v-img :src="getImageUrl(category, optionIndex, imageIndex)" @click="updateAvatar(category, optionIndex, imageIndex)" :style="{ cursor: 'pointer' }" :height="60" :width="60"/>
</v-col>
</v-row>
</v-container>
</v-tab-item>
<v-img :src="avatarUrl" />
</template>
<script>
const AVATAAARS_URL = 'https://avataaars.io/';
const CATEGORIES = [
'topTypes',
'facialHairTypes',
// add more categories here
];
const CATEGORY_OPTIONS = {
topTypes: [
['NoHair', 'Eyepatch', 'Hat'],
['Hijab', 'Turban', 'WinterHat1'],
// add more options here
],
facialHairTypes: [
['Blank', 'BeardMedium', 'BeardMajestic'],
['BeardLight', 'BeardMagestic', 'MoustacheFancy'],
// add more options here
],
// add more categories with their respective options here
};
export default {
data: () => ({
activeCategory: CATEGORIES[0],
categories: CATEGORIES,
options: CATEGORY_OPTIONS,
avatarUrl: null,
selectedIndexes: JSON.parse(localStorage.getItem('avatarSelectedIndexes') || '{}'),
}),
computed: {
selectedOptions() {
return Object.values(this.selectedIndexes);
},
},
methods: {
getImageUrl(category, optionIndex, imageIndex) {
const selectedIndexes = { ...this.selectedIndexes };
if (!selectedIndexes[category]) {
selectedIndexes[category] = [];
}
selectedIndexes[category][optionIndex] = imageIndex;
localStorage.setItem('avatarSelectedIndexes', JSON.stringify(selectedIndexes));
const categoryOptions = this.options[category][optionIndex];
const option = categoryOptions[imageIndex];
return this.generateImageUrl(category, option);
},
updateAvatar(category, optionIndex, imageIndex) {
this.avatarUrl = this.getImageUrl(category, optionIndex, imageIndex);
},
generateImageUrl(category, option) {
const selectedOptions = Object.values(this.selectedIndexes);
const optionIndex = this.options[category].findIndex((categoryOptions) => categoryOptions.includes(option));
const imageIndex = this.options[category][optionIndex].indexOf(option);
const query = selectedOptions.map((optionIndexes) => optionIndexes.join('_')).join('=');
return `${AVATAAARS_URL}${category}/${option}/${imageIndex}${query && `?${query}`}`;
},
},
};
</script>
This code displays the avataaars categories as vuetify tabs and their respective options as image items inside the item-group components. Each time the user changes an option, the main avatar image gets updated. After the avatar is built, it is stored in local storage and every time the app is restarted, the corresponding item-group elements are preselected according to the options of the stored avatar. The generateImageUrl function updates just one URL. The option images are computed, so the user can see how each option would change the avatar.
Note: This code is not complete and only serves as a starting point. You might have to tweak it and add some additional functionality to fit your specific needs.