Vue-router: v-link dynamic params

Created on 6 Nov 2015  路  4Comments  路  Source: vuejs/vue-router

My Vue component's data looks like

{
  data: function() {
    return {
       one: 'a'
    }
  }
}

in template, I use v-link to dynamic generate my link

<a v-link="/home/{{one}}">{{one}}</a>

Sadly, this doesn't work. When I try to custom a directive, it warns me

[Vue warn]: v-plink="/one/{{one}}": attribute interpolation is not allowed in Vue.js directives and special attributes.

How can I use v-link to generate dynamic link? or there is another way to do this? thanks.

Most helpful comment

Use regular JavaScript expressions for directives:

<a v-link="'/home/' + one">{{ one }}</a>

All 4 comments

+1

Use regular JavaScript expressions for directives:

<a v-link="'/home/' + one">{{ one }}</a>

Thanks @JosephSilber . I missed the 1.0 binding syntax. In 1.0, literal directives are not valid and mustache tags can only appear inside native attributes.

@JosephSilber thanks you save my life

Was this page helpful?
0 / 5 - 0 ratings