JSFiddle - React, Tailwind, and code Playground

by novisshriv

HTML

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
  
  <div id="app">
    <div class="demo" @click = 'attachred = !attachred' :class ="{red:attachred, blue: !attachred}"></div>
    <div class="demo" @click= "attachred = !attachred" :class = "divClasses"></div>
    <div class="demo" :class ="[color, {red: attachred}]"></div>
    <hr>
  <input type="text" v-model ="color">
    
  </div>
  
</body>
</html>

CSS

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

.red{
  background-color:red;
}

.green{
  background-color:green;
}

.blue{
  background-color: blue;
}

JavaScript

new Vue({
 el: '#app',
 data:{
 	attachred: false,
  color: 'green'
 },
 computed:{ // computed because since it depends on the attach red property it needs to be computed
 divClasses: function(){
 	return {
  	red: this.attachred,
    blue: !this.attachred
  }
 }
 
 }
})