当前位置: 首页 > news >正文

css 里面写if else 条件判断

  • 定义时使用 @mixin name(params) 声明
  • 调用时通过 @include name(args) 引入样式 
  • mixins.scss文件中:
    @import './variables.scss';// 弹性布局
    @mixin flex($direction: row, $justify: flex-start, $align: stretch, $wrap: nowrap) {display: flex;flex-direction: $direction;justify-content: $justify;align-items: $align;flex-wrap: $wrap;
    }// 居中对齐
    @mixin flex-center {display: flex;justify-content: center;align-items: center;
    }// 两端对齐
    @mixin flex-between {display: flex;justify-content: space-between;align-items: center;
    }// 文本截断
    @mixin text-truncate {overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
    }// 多行文本截断
    @mixin text-truncate-multiline($lines: 2) {overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: $lines;-webkit-box-orient: vertical;
    }// 响应式布局
    @mixin responsive($breakpoint) {@if $breakpoint == sm {@media (min-width: $breakpoint-sm) { @content; }} @else if $breakpoint == md {@media (min-width: $breakpoint-md) { @content; }} @else if $breakpoint == lg {@media (min-width: $breakpoint-lg) { @content; }} @else if $breakpoint == xl {@media (min-width: $breakpoint-xl) { @content; }}
    }// 状态颜色
    @mixin status-color($status) {@if $status == 'normal' or $status == '正常' {background-color: $color-success;color: $color-white;} @else if $status == 'warning' or $status == '警告' {background-color: $color-warning;color: $color-dark;} @else if $status == 'error' or $status == '异常' {background-color: $color-danger;color: $color-white;} @else {background-color: $color-secondary;color: $color-white;}
    } 

    引用的vue文件:

    <template><div class="switch-node"><!-- 交换机图标和名称 --><div class="d-flex align-items-center mb-2"><div class="switch-node__icon"><svg class="switch-node__icon-svg" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" /></svg></div><div class="switch-node__content"><p class="switch-node__title" :title="nodeData.label">{{ nodeData.label }}</p><p class="switch-node__subtitle">{{ nodeData.district }}</p></div></div><!-- 状态指示器 --><div class="switch-node__footer"><span>状态:</span><span class="switch-node__status" :class="statusClass"><span class="switch-node__status-indicator"></span>{{ nodeData.status }}</span></div><!-- 设备计数指示器 --><div class="switch-node__devices">设备: {{ nodeData.devices ? nodeData.devices.length : 0 }}</div></div>
    </template><script>
    export default {name: 'SwitchNode',props: {nodeData: {type: Object,required: true}},computed: {statusClass() {switch(this.nodeData.status) {case '正常': return 'status-normal';case '警告': return 'status-warning';case '异常': return 'status-error';default: return '';}}}
    }
    </script><style lang="scss" scoped>
    @import '@/assets/styles/variables.scss';
    @import '@/assets/styles/mixins.scss';.status-normal {@include status-color('正常');
    }.status-warning {@include status-color('警告');
    }.status-error {@include status-color('异常');
    }
    </style> 

http://www.xdnf.cn/news/607555.html

相关文章:

  • 量化indicators指标
  • @JsonFormat时区问题
  • 从渗透测试角度分析 HTTP 数据包
  • 3D打印仿造+ AI大脑赋能,造出会思考的全景相机
  • 【摄影测量与遥感】卫星姿态角解析:Roll/Pitch/Yaw与Φ/Ω/Κ的对应关系
  • 第十天 高精地图与定位(SLAM、RTK技术) 多传感器融合(Kalman滤波、深度学习)
  • PyTorch中TensorBoardX模块与torch.utils.tensorboard模块的对比分析
  • Teensy LC 一款由 PJRC 公司开发的高性能 32 位微控制器开发板
  • vue-pure-admin动态路由无Layout实现解决方案
  • 【大数据】宽表和窄表
  • Python 实现基于 OpenAI API 的文章标题自动生成评论
  • ASUS华硕ROG枪神9P笔记本G815LP(G615LW,G635LR,G835LX)原装出厂Win11系统,开箱状态oem系统
  • 【趣味Python】第8课:小汽车游戏
  • 在公司快速查看与固定内网IP地址的完整指南
  • SpringAI(GA版)的Advisor:快速上手+源码解读
  • ProfiNet转Ethernet/IP网关选型策略适配西门子S7-1500与罗克韦尔ControlLogix5580的关键指标对比
  • 架构师论文《论软件可靠性模型的设计与实现》
  • 画思维导图的方法分享
  • 镭神N10P SLAM算法选型
  • 《进化陷阱》--AI 生成文章 《连载 2》
  • Java Lock使用
  • 安全运营与威胁对抗体系
  • 【分布式文件系统】FastDFS
  • 语音合成之十五 语音合成(TTS)分句生成拼接时的响度一致性问题:现状、成因与对策
  • 拉普拉斯算子过零点边缘检测原理以及抑制伪边缘的方法
  • 农业机械化、电气化和自动化知网英文普刊:1天录用,2周见刊发表!
  • 全链路解析:影刀RPA+Coze API自动化工作流实战指南
  • 静态时序分析与约束
  • Python 和 matplotlib 保存图像时,确保图像的分辨率和像素符合特定要求(如 64x64),批量保存 不溢出内存
  • 单机Kafka配置ssl并在springboot使用