Home Examples Charts Dashboard Projects Menu

Vue.js examples
Learn Vue.js

vuejs class

Related course:
Fullstack Vue: The Complete Guide to Vue.js

You can bind data to a class. This allows you to toggle a class dynamically.
You can use v-bind:class to bind a variable to a class.

If you have a variable, isActive, you would have this template:

<div v-bind:class="{ active: isActive }">
Class example

vuejs class example

The example below will load the stylesheet class if the apps variable is set to true.

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<!-- include vue -->
<script src="//unpkg.com/vue"></script>
.active {
background: green;
<div id="app">
<div v-bind:class="{ active: isActive }">
Class example {{ isActive }}
<script src="app.js"></script>

In your Vue Instance add the variable:

new Vue({
el: '#app',
data: {
isActive: true
methods: {

← vuejs components vuejs dropdown →


© vuejsexamples.net - Privacy Policy - Cookie Policy