I
I
Ivan2020-12-08 10:48:40
Vue.js
Ivan, 2020-12-08 10:48:40

How to add a variable to the href link attribute in vue js?

I do something like this:

<span> Вы получили предложение от пользователя <a href="users/{{ item.slug }}">{{ item.name }}</a></span>


where item.slug is the variable to be attached. Doesn't work. Tried ${ item.slug }it, not the same. How to pass a variable there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2020-12-08
@Djonson86

Tag attributes must be constructed using v-bind (v-bind:href or :href).
If an object is used inside quotes, then it is perceived as an attribute selector, if a string, then the string is glued together in the final value of the attribute.

<span> Вы получили предложение от пользователя <a v-bind:href="'users/' + item.slug">{{ item.name }}</a></span>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question