乐趣区

关于vue.js:Vue2动态绑定类名与样式

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
  <div id="app">
    <!-- <ul class="list">
      <li class="item active">1</li>
      <li class="item">2</li>
      <li class="item">3</li>
    </ul> -->
    <!-- <ul class="list">
      <li class="item" :class="{'active':isActive}">1</li>
      <li class="item">2</li>
      <li class="item">3</li>
    </ul> -->
    <ul class="list">
      <li class="item" :class="['active']">1</li>
      <li class="item" :style="css">2</li>
      <li class="item">3</li>
    </ul>
  </div>
</body>
<script>
  var app = new Vue({
    el: '#app',
    data: {
      isActive: true,
      css: {color: 'red',}
    }
  })
</script>
</html>
退出移动版