<div id="app">
<button v-for="tab in tabs"
v-bind:key="tab.id"
v-on:click="currentTab = tab.id">
<span v-bind:class="tab.id">{{ tab.text }}</span>
</button>
<component v-bind:is="currentTabComponent"></component>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
Vue.component('tab-home', { template: '<div>ホームのコンポーネントです。</div>' })
Vue.component('tab-posts', { template: '<div>投稿のコンポーネントです。</div>' })
Vue.component('tab-archive', { template: '<div>一覧のコンポーネントです。</div>' })
Vue.component('tab-comment', { template: '<div>コメントのコンポーネントです。</div>' })
new Vue({
el: '#app',
data: {
currentTab: 'home',
tabs: [
{id:'home',text:"ホーム"},
{id:'posts',text:"投稿"},
{id:'archive',text:"一覧"},
{id:'comment',text:"コメント"},
]
},
computed: {
currentTabComponent: function () {
return 'tab-' + this.currentTab;
}
}
})
</script>