I have a form where I either have 1 client or 2 clients. I created a component for choosing the count, and another one for displaying client information form are (so if 2 clients, with v-for, 2 forms).
<div id="root">
<count-section></count-section> // also emits the client count
<infos
v-for="(count, index) in total"
:key="index"
v-bind:index="count">
</infos>
</div>
After seting up props, I could catch the count
in my component.
In a innerhtml, this one is working working:
<h5>Person {{ count }} Info</h5>
Then I tried to generate an attribute combining string and it gave me error.
<input name="name-client-{{count}}"
name="name-client-{{count}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of , use .
What is the proper way of achieving it? Did I thought about the flow the wrong way? I thought of having name-client-1 and name-client-2 together as bunch of all the other fields with same structure and use a for-loop on the backend.
Concatenation operators join multiple strings into a single string. There are two concatenation operators, + and & . Both carry out the basic concatenation operation, as the following example shows.
You can concatenate a list of strings into a single string with the string method, join() . Call the join() method from 'String to insert' and pass [List of strings] . If you use an empty string '' , [List of strings] is simply concatenated, and if you use a comma , , it makes a comma-delimited string.
Use the += operator and the concat() method to append things to Strings. operator, these operators are handy for assembling longer strings from a combination of data objects.
The “+” operator with a String acts as a concatenation operator. Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object. In-fact adding a double value to String is the easiest way to convert a double value to Strings.
Using ES6 template string :name="`name-client-${count}`"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With