Hello i'm trying to make a global dynamic component with some extra features. my question is :How can i show/hide v-tab depend on the v-checkbox value? this is my code:
<template>
<div>
<v-tabs v-model="activeTab">
<v-tab v-for="(item, index) in tabs" :key="`${index}-tab`" v-if="checked">
{{ item.name }}
</v-tab>
<v-tab-item v-for="(item, index) in tabs" :key="`${index}-tab`">
<v-card flat>
{{ item.name }}
</v-card>
</v-tab-item>
<v-menu
v-model="menu"
:close-on-content-click="false"
:nudge-width="200"
offset-x
>
<template v-slot:activator="{ on, attrs }">
<div class="d-flex align-center">
<v-btn icon v-bind="attrs" v-on="on">
<v-icon>mdi-eye</v-icon>
</v-btn>
</div>
</template>
<v-card>
<v-list>
<v-list-item-group v-model="selectedTabs" multiple>
<template v-for="(item, index) in tabs">
<v-list-item :key="`${index}-tab`">
<v-list-item-action class="ma-0">
<v-checkbox
:key="`${index}-tab`"
@click="hidecont(item)"
></v-checkbox>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title v-text="item.name"></v-list-item-title>
</v-list-item-content>
</v-list-item>
</template>
</v-list-item-group>
</v-list>
</v-card>
</v-menu>
</v-tabs>
</div>
</template>
<script>
export default {
data() {
return {
activeTab: 0,
selectedTabs: [],
menu: false,
checked: false,
tabs: [
{
name: "tab1"
},
{
name: "tab2"
},
{
name: "tab3"
}
]
};
},
methods: {
hidecont(item) {
console.log("item");
// i know this will not work in my case
this.checked = !this.checked;
}
}
};
</script>
How it should be : for example when the checkbox(tab1) checked/unchecked => the v-tab(tab1) should be hidden/visible according to the related checkbox... i tried several ways but it doesn't matter in which checkbox i click i got all the v-tabs hidden or visible, the problem hier is i dont know how to pass the right index to the v-tabs component from the check box...
i can not modify the array of Objects because it comes from a rest Api, this is just an example to simplify the issue. it would be great if i can use the item.index or item.name to make it work without modifing the array...
would be so thankfull if some one can help