Created
October 18, 2017 19:14
-
-
Save ekrist1/6e1a65154a1bad4e7ee3a0f788eb546a to your computer and use it in GitHub Desktop.
Vue Bulma Laravel Tabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <div> | |
| <Tabs :tabsInitial="tabData"></Tabs> | |
| <div class="contactOverview" v-if="selectedContentTab === 'Oversikt'"> | |
| <p>Working</p> | |
| </div> | |
| </div> | |
| </template> | |
| <script> | |
| import Tabs from './utilities/Tabs.vue'; | |
| export default { | |
| components: { Tabs }, | |
| data () { | |
| return { | |
| tabData: [ | |
| {id: 0, name: 'Oversikt',}, | |
| {id: 1, name: 'Looger'}, | |
| {id: 2, name: 'Filer'}, | |
| {id: 3, name: 'Timer'}, | |
| ], | |
| selectedContentTab: 'Oversikt' | |
| } | |
| }, | |
| mounted() { | |
| this.$eventHub.$on('showTabContentIndex', this.showTabContentIndex) | |
| }, | |
| methods: { | |
| showTabContentIndex (tab) { | |
| this.selectedContentTab = tab.name | |
| } | |
| } | |
| } | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <div> | |
| <div class="tabs"> | |
| <ul> | |
| <li v-for="tab in tabs" :key="tab.id" :class="{ 'is-active': isActivated(tab) }"><a @click="selectTab(tab)">{{ tab.name }}</a></li> | |
| </ul> | |
| </div> | |
| </div> | |
| </template> | |
| <script> | |
| export default { | |
| props: { | |
| tabsInitial: { | |
| type: Array, | |
| } | |
| }, | |
| data () { | |
| return { | |
| tabs: this.tabsInitial, | |
| selectedTabIndex: 0, | |
| } | |
| }, | |
| methods: { | |
| selectTab(tab) { | |
| this.selectedTabIndex = tab.id; | |
| this.$eventHub.$emit('showTabContentIndex', tab) | |
| }, | |
| isActivated(tab) { | |
| return tab.id === this.selectedTabIndex; | |
| } | |
| } | |
| } | |
| </script> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instruction how to use the Vue Bulma Laravel tab component:
disclaminer: work-in-progress
The Bulma CSS framework comes without javascript, and I made this reusable component to add active state to
the tabs and for toggling tab-content. You could use the eventbus to initiate a call to a API to load data when switching tabs.
Add a global eventbus in your app.js file:
Vue.prototype.$eventHub = new Vue();Add your parent-component to you app.js file:
Vue.component('ShowContact', require('./components/ShowContact.vue'));