0

What is the correct way to add custom href to each link in the list?

For example, i want that link: 'News' would have href="http://example.com/news".

Is there a possible way to do something like that:

{ link: 'News', href: 'http://example.com/news' }

And render it like that:

<a v-bind:href="{{ a.href }}" v-bind:class="[foot]" v-for="a in news">{{ a.link }}</a>

What i have:

JS

var footer = new Vue({
 el: '.footer',
 data: {
    foot: 'footmenu',
    news: [
       { link: 'News', },
       { link: 'Latest' },
       { link: 'Business news' },
       // etc
    ],
    business: [
       { link: 'Vets' },
       { link: 'Companion animal' },
       { link: 'Equine' },
       // etc
    ],
    // etc
});

HTML

<a v-bind:class="[foot]" v-for="a in news">{{ a.link }}</a>

1 Answer 1

1

It should be like following:

<a v-bind:href="a.href" v-bind:class="[foot]" v-for="a in news">{{ a.link }}</a>

as you don't need braces along with v-bind. From the documentation:

Dynamically bind one or more attributes, or a component prop to an expression.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It is working. I will accept answer in 10min.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.