2

I'm creating a test Component in Vue.js. I want to pass a parameter to use in my template as follows:

Vue.component('test', {
   props: ['href'],
   template: '<li><a href="{{href}}"><slot></slot></a></li>'
});

In my html file:

<test href="/">Tvest</test>

But the property href is not binding to the attribute.

<li><a href="{{href}}">Tvest</a></li>

How can I do it properly in Vue.js?

0

2 Answers 2

3

You need to get rid of the brackets around href and specify that you are binding a data property by using the v-bind directive:

<li><a v-bind:href="href"><slot></slot></a></li>
0
2

Use the v-bind directive to set the prop:

<a v-bind:href="href"><slot></slot></a>

or shortcut

<a :href="href"><slot></slot></a>

2
  • My component disappear when I put in this way Commented Jul 25, 2017 at 20:27
  • I copied your brackets... :( . Of course brackets are a two way binding that only works as innerContent of html-elements.
    – reinerBa
    Commented Jul 25, 2017 at 20:43

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.