v-bind綁定class(day6)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .active{
      color: red;
    }
  </style>
</head>
<body>
  <div id="app">
  <h2 class="title" v-bind:class="{active: isActive,line: isLine}">{{message}}</h2>
  <h2 class="title" v-bind:class="getClasses()">{{message}}</h2>
  <button v-on:click="btnClick">🔘</button>
  </div>
  <script src="js/vue.js">
  </script>
  <script>
     const app = new Vue({
        el: '#app',
        data: {
          message : 'hello',
          isActive: true,
          isLine :true,
        },
        methods: {
          btnClick: function(){
            this.isActive = !this.isActive
          },
          getClasses: function(){
            return {active: this.isActive,line: this.isLine}
          }
        }
     })
  </script>
</body>
</html>
 <div id="app">
  <h2 :class="[active,line]">{{message}}</h2>
  </div>
  <script src="js/vue.js">
  </script>
  <script>
     const app = new Vue({
        el: '#app',
        data: {
          message: 'hello',
          active: 's',
          line: 'a'
        }
     })
  </script>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章