vue v-bind:class

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
  </head>

  <style type="text/css">
    .active {
      color: red;
    }
  </style>

  <body>
    <div id="app">
      <p v-bind:class="{active: isActive}">{{ message }}</p>
      <button type="button" v-on:click="onClick">点我</button>
    </div>

    <script>
      const app = new Vue({
        el: '#app',
        data: {
          message: 'Hello Vue.js!',
          isActive: true
        },
        methods: {
          onClick: function() {
            this.isActive = !this.isActive;
          }
        }
      })
    </script>
  </body>
</html>

posted @ 2021-06-30 19:27  thomas_blog  阅读(46)  评论(0编辑  收藏  举报