Vue Styling 4

by nevkatz

HTML

<script src="https://npmcdn.com/vue/dist/vue.js"></script>

<div id="app">
   <div class="demo" @click="attachRed = !attachRed" :class="divClasses"></div>
   <div class="demo" :class="[color,{red: attachRed}]"></div>
   <div class="demo" :class="color"></div>
<hr>
<input type="text" v-model="color">
</div>

CSS

.demo {
  width: 100px;
  height: 100px;
  background-color: grey;
  display: inline-block;
  margin: 10px;
}
.green {
  background-color: green;
}
.red {
  background-color: red;
}

.blue {
  background-color: blue;
}

JavaScript

new Vue({
   el:'#app',
   data:{
     color: 'green',
     attachRed:false
   },
   computed:{
     divClasses:function(){
        return {
           red:this.attachRed,
           blue:!this.attachRed
        }
     }
   }
})