Determine active tab using a data value

This commit is contained in:
Oliver Davies 2018-11-20 20:16:42 +00:00
parent 0f2e3aed54
commit 5923ff2977

View file

@ -21,11 +21,11 @@
<div <div
class="px-1 sm:pl-0 mb-1 md:mb-0 inline-block w-full sm:w-1/3 md:w-auto" class="px-1 sm:pl-0 mb-1 md:mb-0 inline-block w-full sm:w-1/3 md:w-auto"
:key="link.title" :key="link.title"
v-for="link in links" v-for="(link, index) in links"
> >
<a <a
class="block text-sm no-underline text-black px-3 py-2 rounded-lg md:rounded-none md:rounded-t-lg sm:text-center" class="block text-sm no-underline text-black px-3 py-2 rounded-lg md:rounded-none md:rounded-t-lg sm:text-center"
:class="[ link.active ? 'bg-white' : 'bg-blue-lighter hover:bg-white' ]" :class="[ index == activeTab ? 'bg-white' : 'bg-blue-lighter hover:bg-white' ]"
:href="link.href" :href="link.href"
> >
{{ link.title }} {{ link.title }}
@ -41,38 +41,32 @@
export default { export default {
data: function () { data: function () {
return { return {
activeTab: 0,
open: false, open: false,
links: [ links: [
{ {
title: 'Home', title: 'Home',
href: '#0', href: '#0',
active: true,
}, },
{ {
title: 'Drupal', title: 'Drupal',
href: 'https://www.drupal.org', href: 'https://www.drupal.org',
active: false,
}, },
{ {
title: 'Vue.js', title: 'Vue.js',
href: 'https://vuejs.org', href: 'https://vuejs.org',
active: false,
}, },
{ {
title: 'Tailwind CSS', title: 'Tailwind CSS',
href: 'https://tailwindcss.com', href: 'https://tailwindcss.com',
active: false,
}, },
{ {
title: 'View code on GitHub', title: 'View code on GitHub',
href: 'https://github.com/opdavies/rebuilding-bartik', href: 'https://github.com/opdavies/rebuilding-bartik',
active: false,
}, },
// { // {
// title: 'Read blog post', // title: 'Read blog post',
// href: 'https://github.com/opdavies/rebuilding-bartik', // href: 'https://github.com/opdavies/rebuilding-bartik',
// active: false,
// }, // },
] ]
} }