15

I have a vue component to render nav list, and pass nav list, each item includes title and link:

<template>
  <ul>
    <li v-for="item in list"><a v-link="{{ path: item.link }}"></a></li>
  </ul>
</template>

<script>
  export default {
    props: ['list']
  }
</script>

I try pass variable item.link to v-link path, but failed.

get this warn:

[Vue warn]: v-link="{{ path: item.link }}": attribute interpolation is not allowed in Vue.js directives and special attributes.

what should i do if pass variable to v-link path?

thanks for reading :)

3 Answers 3

23

I used the following with vue-router 2.x:

<router-link :to="{path: '/applications/' + currentApplicationId}" class="nav-link">Overview</router-link>

More documentation can be found here.

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

Comments

21

Shorter way would be:

<router-link :to="`/applications/${currentApplicationId}`">Overview</router-link>

1 Comment

I would argue that this is the appropriate answer for readability, router link, and ease of use
11

the statement in v-link doesn't need “Mustache” syntax.

<li v-for="item in list"><a v-link="{ path: item.link }"></a></li>

you can see http://router.vuejs.org/en/index.html

Comments

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.