<p :style="{width:'4px',height: '24px',background: '#f7ce51'}"></p>
<p:style="{height: '400px','overflow-y': 'auto','background-color': '#f3f3f3',padding: '15px'}"></p>
 
1、三元运算符判断
<div :style="{ 'opacity': !editableCheckNum ? 0.5 : 1 }">555</div>
 
2、动态设置class
<div :class="activeMachineId === machineItem.machineId?'activeStyle':'machineBar'" v-for="(machineItem,machineIndex) in machineList" @click="clickMachineEvent">    
    <p>{{machineItem.name}}</p>    
    <p :style="machineStatusStyle(machineItem.status)"></p>
</div>
 
3、方法判断
    <div class="machineBigBar machineList">    
        <div class="machineBar" v-for="(machineItem,machineIndex) in processItem.machineList" :key="machineIndex">        
            <p>{{machineItem.name}}</p>        
            <p :style="machineStatusStyle(machineItem.status)"></p>    
        </div>
    </div>  
    methods:{    
        machineStatusStyle(e){        
            console.log('值',e)        
            if(e === 1){            
                return {                
                    width:'14px',height:'16px',                
                    background:"url('/src/images/time.png') no-repeat center",                 
                    marginLeft: '10px'            
                }        
            }else if(e === 2){            
                return {                
                    width:'14px',
                    height:'16px',                
                    background:"url('/src/images/time.png') no-repeat center",                 
                    marginLeft: '10px'            
                }        
            }else if(e === 3){            
                return {                
                    width:'14px',
                    height:'16px',                
                    background:"url('/src/images/time.png') no-repeat center",                 
                    marginLeft: '10px'            
                }        
            };    
        }
4、数组绑定
    <div :class="[activeStyle, defaultStyle]"></div>
 
5、computed结合es6对象的计算属性名方法

<div :class="dynClass">测试</div>

 
<script>     
    let activeStr = 'activeStyle';     
    let isAActive = true;     
    let isBActive = false;     
    export default { 
        computed: { 
            dynClass () { 
                return [ 
                    `${activeStr}`, 
                    {                         
                        ['name']: isAActive,    // 属性是条件,条件成立,则创建该属性
                        ['age']: isBActive                     
                    }                 
                ]             
            }         
        },
    }
</script>
解析: <div class="activeStyle name">测试</div>

vue 动态样式的更多相关文章

  1. vue动态样式设置

    思路: 通过 v-bind:class="true ? style1 : style2 " 配合三元表达式完成样式的切换 具体实现 //return设置控制的参数 //有多个需要样 ...

  2. vue中动态样式不起作用? scoped了解一下

    vue中style标签使用属性scoped的注意事项 style上添加属性scoped可以实现样式私有化,但是在使用动态样式时,样式会不起作用.可以先去掉scoped

  3. vue基础-动态样式&表单绑定&vue响应式原理

    动态样式 作用:使用声明式变量来控制class和style的值 语法: :class/:style 注意:尽可能不要把动态class和静态class一起使用,原因动态class起作用的时间会比较晚,需 ...

  4. vue 绑定样式的几种方式

    vue 绑定样式 对象语法 1.v-bind:class设置一个对象,动态切换class <div :class="{'active':isActive}">xxx&l ...

  5. vue.js样式绑定

    vue.js样式绑定 class 与 style 是 HTML 元素的属性,用于设置元素的样式,我们可以用 v-bind 来设置样式属性. Vue.js v-bind 在处理 class 和 styl ...

  6. 10.Vue.js 样式绑定

    Vue.js 样式绑定 Vue.js class class 与 style 是 HTML 元素的属性,用于设置元素的样式,我们可以用 v-bind 来设置样式属性. Vue.js v-bind 在处 ...

  7. 深入理解脚本化CSS系列第五篇——动态样式

    前面的话 很多时候,DOM操作比较简单明了,因此用javascript生成那些通常原本是HTML代码生成的内容并不麻烦.但由于浏览器充斥着隐藏的陷阱和不兼容问题,处理DOM中的某些部分时要复杂一些,比 ...

  8. DOM动态脚本和动态样式

    动态脚本 [定义] 在页面加载时不存在,但将来的某一时刻通过修改DOM动态添加的脚本. [方式] [1]插入外部文件方式 var script = document.createElement(&qu ...

  9. Less (一种动态样式语言)

    Less (一种动态样式语言). LESS是一种由Alexis Sellier设计的动态层叠样式表语言,受Sass所影响,同时也影响了 Sass的新语法:SCSS. LESS是开源的,其第一个版本由R ...

随机推荐

  1. webrtc aecd算法解析一(原理分析)

    webrtc的回声抵消(aec.aecm)算法主要包括以下几个重要模块: 回声时延估计 NLMS(归一化最小均方自适应算法) NLP(非线性滤波) CNG(舒适噪声产生) 回声时延估计 这张图很多东西 ...

  2. AI - TensorFlow - 第一个神经网络(First Neural Network)

    Hello world # coding=utf-8 import tensorflow as tf import os os.environ[' try: tf.contrib.eager.enab ...

  3. 性能测试工具 wrk 使用教程

    文章首发自个人微信公众号:小哈学Java 个人网站地址:https://www.exception.site/wrk 被面试官经常问到之前开发的系统接口 QPS 能达到多少,经常给不出一个数值,支支吾 ...

  4. 【Android Studio安装部署系列】二十一、Android studio将项目上传到github中

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 两个相关概念:git和github Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.Git ...

  5. jquery快速入门(四)

    jQuery 遍历 向上遍历 DOM 树 parent() parent() 方法返回被选元素的直接父元素.该方法只会向上一级对 DOM 树进行遍历. parents() parents() 方法返回 ...

  6. SLAM+语音机器人DIY系列:(二)ROS入门——9.熟练使用rviz

    摘要 ROS机器人操作系统在机器人应用领域很流行,依托代码开源和模块间协作等特性,给机器人开发者带来了很大的方便.我们的机器人“miiboo”中的大部分程序也采用ROS进行开发,所以本文就重点对ROS ...

  7. async/Await使用和原理

    await/async是.NetFramework4.5出现的,是语法糖,由编译器提供的功能! await/async 是C#保留关键字,通常是成对出现,一般的建议是:要么不用,要么用到底 async ...

  8. 第一册:lesson 121.

    原文:The man in a hat. question:Why didn't Caroline  recognize the customer straight away? I bought tw ...

  9. 第一册:lesson 115.

    原文:Knock,Knock! question:What does Jim have to drink? Isn't there anyone at home? I'll knock again , ...

  10. 类和对象,以及 LeetCode 每日一题

    所有类都是引用类型. 1 定义类 类是某一批对象的抽象. 1.1 定义类的语法: [修饰符] class 类名{ 零到多个构造器定义 零到多个成员变量 零到多个方法 } 对于一个类定义而言,可以包含三 ...