将 isActive 设置为 true 显示了一个绿色的 div 块,如果设置为 false 则不显示:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://unpkg.com/vue@next"></script>
    <title>Document</title>
    <style>
      .active {
        width: 100px;
        height: 100px;
        background: green;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div :class="{ 'active': isActive }"></div>
    </div>

    <script>
      const app = {
        data() {
          return {
            isActive: true,
          }
        },
      }

      Vue.createApp(app).mount('#app')
    </script>
  </body>
</html>

image

posted @ 2022-04-28 16:00  wjxuriel  阅读(192)  评论(0)    收藏  举报