I am aiming to create a navigation menu, where each div
will have a header and a list of links
<div>
<h1>Header</h1>
<ul>
<li>
<a href="#">Link</a>
</li>
</ul>
</div>
I want to add the link data to the data()
in Vue, and I have attempted it like so:
<script>
export default {
data() {
return {
links: {
columns: [
{
heading: 'Feature',
attr: [
{
text: 'Something'
}
]
}
]
}
}
}
}
</script>
And here is the HTML with the attempt to use v-for
<template>
<div class="pt-8 sm:pt-16 h-screen navigation-background-gradient">
<nav class="mx-4 sm:mx-48">
<div class="sm:grid sm:grid-cols-3 sm:gap-56">
<div v-for="link in links.columns">
<h1 class="mb-5 text-white font-semibold font-montserrat tracking-wider uppercase text-2xl text-shadow-glow">{{ link.heading }}</h1>
<ul class="space-y-4">
<li>
<a class="block text-lg text-menu-link font-inter font-medium tracking-wider" href="#">{{ link.attr }}</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</template>
So I can access the heading
fine, but I can't access attr.text
If I echo out attr.text
I get [ { "text": "Something" } ]
but I aren't sure how to get to it. I thought I may need to do another loop, as it's an array, but I couldn't work out the correct combination to use to make it show.
I feel like I am close and missing something obvious, but I can't see it. Can anyone suggest me where am I doing wrong ?