2

I'm new to Vuejs2.0 and trying to bind multiple css classes to a table row element.

Here's my view (and my attempt):

<tr v-for="icon in icons">
    <td><i class="fa fa-" v-bind:class="icon.css"></i></td>
    <td>{{icon.name}}</td>
</tr>

The td element with the css classes should be successfully rendered as so:

<td><i class="fa fa-car"></i></td>

Here's my model/data (snipped for brevity):

new Vue({
    el: '#app',
    data: {
        icons: [ 
            { "name": "Car", "css": "car" }, { "name": "Airplane", "css": "airplane" } 
        ]
    }
});

How would I get this successfully rendered ? Thank you.

1 Answer 1

2
<tr v-for="icon in icons">
    <td><i class="fa" :class="'fa-' + icon.css"></i></td>
    <td>{{icon.name}}</td>
</tr>

Or

<tr v-for="icon in icons">
    <td><i :class="'fa fa-' + icon.css"></i></td>
    <td>{{icon.name}}</td>
</tr>
Sign up to request clarification or add additional context in comments.

2 Comments

@redshift You're welcome. Then please mark the answer as correct and finish this one.
I just did. Also, here's a similar question now: stackoverflow.com/q/42348292/2420614

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.