Chrome Extension

Add class to an element condition based in Vuejs

<template>
    <div v-bind:class="{'show_me': index === 0}">
        Hello World
    </div>
</template>

<script>
    export default {
        data: function() {
            return {
                index: 0
            }
        }
    }
</script>

In Vuejs, if you want to add CSS class to an element, you can use v-bind:class attribute of Vuejs. In the code snippet, we have added class "show_me" based on index value that is defined in data when exporting this Vue component.

Was this helpful?
0 Comments
Never leave your website again in search of code snippets by installing our chrome extension.
Open Code Manager