zoukankan      html  css  js  c++  java
  • vue 添加样式分几种方法

    一.

    <body>
    <div id="app">
      <div v-bind:class="{ active: isActive }"></div>
    </div>
    
    <script>
    new Vue({
      el: '#app',
      data: {
        isActive: true
      }
    })
    </script>
    

    二.

    <div id="app">
      <div class="static"
         v-bind:class="{ active: isActive, 'text-danger': hasError }">
      </div>
    </div>
    
    <script>
    new Vue({
      el: '#app',
      data: {
        isActive: true,
    	hasError: true
      }
    })
    

      

    三.

    <style>
    .active {
    	 100px;
    	height: 100px;
    	background: green;
    }
    .text-danger {
    	background: red;
    }
    </style>
    </head>
    <body>
    <div id="app">
      <div v-bind:class="classObject"></div>
    </div>
    
    <script>
    new Vue({
      el: '#app',
      data: {
        classObject: {
          active: true,
          'text-danger': true
        }
      }
    })
    

      

      

    四.

    <style>
    .active {
    	 100px;
    	height: 100px;
    	background: green;
    }
    .text-danger {
    	background: red;
    }
    </style>
    </head>
    <body>
    <div id="app">
    	<div v-bind:class="[activeClass, errorClass]"></div>
    </div>
    
    <script>
    new Vue({
      el: '#app',
      data: {
        activeClass: 'active',
        errorClass: 'text-danger'
      }
    })
    </script>
    

      

    五.

    <style>
    .text-danger {
    	 100px;
    	height: 100px;
    	background: red;
    }
    .active {
    	 100px;
    	height: 100px;
    	background: green;
    }
    </style>
    </head>
    <body>
    <div id="app">
    	<div v-bind:class="[errorClass ,isActive ? activeClass : '']"></div>
    </div>
    
    <script>
    new Vue({
      el: '#app',
      data: {
        isActive: true,
    	activeClass: 'active',
        errorClass: 'text-danger'
      }
    })
    </script>
    

      

    六. style内联样式

    <div id="app">
    	<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">菜鸟教程</div>
    </div>
    
    <script>
    new Vue({
      el: '#app',
      data: {
        activeColor: 'green',
    	fontSize: 30
      }
    })
    

      

      

  • 相关阅读:
    HDU 1063 Exponentiation
    HDU 1261 字串数
    HDU 1715 大菲波数
    HDU 1002 A + B Problem II
    csharp 復制DataTable修改某列的值
    解决IE6下透明PNG图片有灰底的解决方案
    webform TextBox以一条横线显示 兼容各主流瀏覽器 .
    SQL 工齡計算
    csharp Format CultureInfo
    Csharp Winform TextBox 樣式以一條橫線顯示
  • 原文地址:https://www.cnblogs.com/lianxisheng/p/10073192.html
Copyright © 2011-2022 走看看