My goal is to create a list of <span>
elements separated by commas using vue.js and v-for.
Is there an easy way to achieve this in vue.js?
In JavaScript, I would typically use users.join(", ")
.
In FreeMarker templates, you can do some very interesting things with lists that I find enjoyable, such as:
<#list users as user>
<span>
${user}<#sep>, </#sep>
</span>
<#else>
<p>No users</p>
</#list>
I have not come across a similar feature in vue.js yet. (Although I understand that the equivalent of the else part can be achieved using v-if and v-else.) Have I overlooked something?
If not, what could be another solution? One idea I had was to use a template to generate the separator only if it's not the last index by comparing the current index to the length of the array. However, this approach may not work when iterating over object properties.