4

I'm trying to attach the values I get from a v-for to attributes in the same tag but with no luck. Here's my code:

 <label 
      v-for="hashtag in hashtags" 
      v-bind:title=`You can filter with {hashtag}`
      v-bind:data-value="hashtag"
 ></label>

Basically the value goes to the title and data-value

1 Answer 1

5

your title binding should have double quotes before and after the expression, and it seems that you want a string interpolation in title, but I don't think it will work.

try this (you can ommit v-bind cus : its a shorthand for it)

<label v-for="hashtag in hashtags"  :title="'You can filter with ' + hashtag" :data-value="hashtag">
   {{ hashtag }}
</label>

https://jsfiddle.net/5sqs5fsq/

Sign up to request clarification or add additional context in comments.

1 Comment

one important thing to notice here is, if you use v-bing/:, the right side of the = must be a javascript valid expression, cus it will be evaluated by vue. :sum="5+5" will be evaluated to number 10. sum="5+5" will be evaluated to string 5+5. With string :title="'a' + 'string'" you need a single quote inside the double quote to make it work.