<template>
<div class="tabs">
<button
v-for="(tab, index) in tabs"
:key="index"
@click="selectTab(index)"
:class="{ active: selectedIndex === index }"
>
{{ tab.name }}
</button>
<div class="tab-content">
<slot :name="tabs[selectedIndex].name"></slot>
</div>
</div>
</template>
<script>
export default {
data() {
return {
selectedIndex: 0,
tabs: [
{ name: 'Tab1' },
{ name: 'Tab2' },
{ name: 'Tab3' }
]
};
},
methods: {
selectTab(index) {
this.selectedIndex = index;
}
}
};
</script>
<style scoped>
.tabs button {
padding: 10px;
margin-right: 5px;
background-color: #f0f0f0;
border: none;
cursor: pointer;
}
.tabs button.active {
background-color: #4CAF50;
color: white;
}
</style>