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

      

      

  • 相关阅读:
    springboot+mybatis实现逆向工程
    关于cookie,session和token
    fiddler手机抓包配置
    js json按key值排序
    关于CSS和CSS3的布局小知识(干货)
    移动端手机上传图片处理
    nginx|gzip_static 安装
    Vue npm run serve linux 持久运行
    Web前端开发标准规范总结
    liunx启动node服务(nodejs+express+mysql+pm2)
  • 原文地址:https://www.cnblogs.com/lianxisheng/p/10073192.html
Copyright © 2011-2022 走看看