Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How pass variable to vue-router v-link

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 :)

like image 366
luotao Avatar asked Sep 06 '16 08:09

luotao


People also ask

How do you pass props in component Vue?

To specify the type of prop you want to use in Vue, you will use an object instead of an array. You'll use the name of the property as the key of each property, and the type as the value. If the type of the data passed does not match the prop type, Vue sends an alert (in development mode) in the console with a warning.


1 Answers

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.

like image 167
czerasz Avatar answered Sep 17 '22 14:09

czerasz