16

I have a vue.js template that has a todo prop. I want to dynamically set the id value of each element. This what I have tried so far, is something like this possible and if not what are some other options?

<canvas class="canvas" id="cv`${{todo.id}}`" width="500" height="700"></canvas> 
Taylor
  • 1,223
  • 1
  • 15
  • 30

2 Answers2

47

This should work.

:id="`cv${todo.id}`"

or

v-bind:id="`cv${todo.id}`"

Or do it the old-school way if the browser doesn't support string interpolation:

:id="'cv' + todo.id"

This is essentially a duplicate but I couldn't determine how to escape the backticks in a comment!

Bert
  • 80,741
  • 17
  • 199
  • 164
  • I was facing problem with laravel project with "{{}}" not working. But you solution solve all of my problem.. thanks a lot. – Anjan Biswas Feb 14 '19 at 06:42
-1

This helped me to solve my problem :

<input v-bind:id="object.value1" v-model="object.value2"/>

lennoxGER
  • 284
  • 1
  • 6