Insert v-for data into class css in VueJs2

0
<template v-for="d in data" >
     <a :key="d.id" class="zone{{d.value}}" href="{{d.code}}" >{{d.name}}</a>
</template>

This example simply does not work, how can I pass the values that are then within "d" to the attributes? How do I resolve this deadlock?

    
asked by anonymous 01.05.2018 / 22:22

1 answer

0

I do not understand the question very well, but I believe the problem is in the way you are using interpolation.

The interpolation "{{}}" is used only between tags, not inside tags, referencing their variables that are within computed or its data () .

In the case of a tag within a attribute the interpolation is not used, but the v-bind: or the colon": ", which is exactly the same as v-bind, but in a shorter way to use it.

Your code in case I think it would look like this:

<template v-for="d in data" >
     <a :key="d.id" class="zone" :class="d.value" :href="d.code" >{{ d.name }}</a>
</template>

I just do not quite understand what you wanted to do exactly in the case of the class attribute, so I assumed that the zone class is static, and d.value will be another dynamic class, using the variable value.

In this case it is okay to have two class attributes in a tag, Vuejs will merge all classes automatically, from dynamic to static.

    
01.05.2018 / 22:53