Damian Hetman
Damian Hetman

Reputation: 382

Binding data in href attibute - VueJS

I have problem with binding data in VueJS. In code below, user.name is working but user.id in href attribute is not.

<ul id="message-user-list">
  <li v-for="user in users">
    <a href="chat.php?user={{ user.id }}">{{ user.name }}</a>
  </li>
</ul>

I also tried this but it doesn't work:

<ul id="message-user-list">
  <li v-for="user in users">
    <a v-bind:href="chat.php?user={{ user.id }}">{{ user.name }}</a>
  </li>
</ul>

What do I do wrong? Help please.

Upvotes: 1

Views: 6043

Answers (1)

Oleg Shleif
Oleg Shleif

Reputation: 740

Try it like this <a :href="'chat.php?user=' + user.id">{{ user.name }}</a>

If you do v-bind: - vue takes everything in quotes for js

Upvotes: 13

Related Questions