• 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
      }
    })
    

      

      

  • 相关阅读:
    【Docker】11 私有仓库
    【Docker】10 容器存储
    【TypeScript】02 面向对象
    【TypeScript】01 基础入门
    【Spring】08 后续的学习补充 vol2
    【Vue】15 VueX
    【Vue】14 UI库
    【Vue】13 VueRouter Part3 路由守卫
    【Vue】12 VueRouter Part2 路由与传参
    【DataBase】SQL50 Training 50题训练
  • 原文地址:https://www.cnblogs.com/lianxisheng/p/10073192.html
Copyright © 2020-2023  润新知