Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string interpolation Vue js [duplicate]

I'm trying to combine a string and a prop to create a unique id for a bootstrap accordion.

I want to combine "collapse" and {{ thread_ref }} to create something like: id="collapse_321"

Vue gives me an error when I try to do this and says to use v-bind.

I have tried that but that only accepts a string of the name of the prop/data, how can I combine a string and data?

like image 874
Brad Avatar asked Dec 03 '22 12:12

Brad


1 Answers

Do it like this:

:id="'collape' + thread_ref"

Anything inside the " " when you bind a property using v-bind or : is javascript. So you can do any single line expressions that you do in JavaScript

like image 62
Vamsi Krishna Avatar answered Dec 06 '22 11:12

Vamsi Krishna