0.4 - 0.3 == 0.1是true??false

你注意过了么?

 

此处的运算结果是false。

 

这个是ruby上给的解释。哈哈,见识了。

 

Float objects have plenty of precision and can approximate 0.1 very well, 
but the fact that this number cannot be represented exactly leads to problems. 
Consider the following simple Ruby expression:

0.4 - 0.3 == 0.1    # Evaluates to false in most implementations

Because of rounding error, the difference between the approximations of 0.4 and 0.3 is 
not quite the same as the approximation of 0.1. This problem is not specific to Ruby: C, 
Java,JavaScript, and all languages that use IEEE-754 floating-point numbers suffer 
from it as well.
 
<template> <div class="sidebar-container" :class="{ &#39;has-logo&#39;: showLogo, collapse: isCollapse }" :style="{ backgroundColor: settings.sideTheme === &#39;theme-dark&#39; ? variables.menuBackground : variables.menuLightBackground, }" > <!-- Logo 区域 --> <logo v-if="showLogo" :collapse="isCollapse" /> <!-- 滚动区域(区分主题滚动条样式) --> <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper"> <el-menu :default-active="activeMenu" :collapse="isCollapse" mode="vertical" :background-color=" settings.sideTheme === &#39;theme-dark&#39; ? variables.menuBackground : variables.menuLightBackground " :text-color=" settings.sideTheme === &#39;theme-dark&#39; ? variables.menuColor : variables.menuLightColor " :active-text-color="settings.theme" :unique-opened="true" :collapse-transition="false" > <sidebar-item v-for="(route, index) in sidebarRouters" :key="route.path + index" :item="route" :base-path="route.path" /> </el-menu> </el-scrollbar> </div> </template> <script> import { mapGetters, mapState } from "vuex"; import Logo from "./Logo"; import SidebarItem from "./SidebarItem"; import variables from "@/assets/styles/variables.scss"; export default { components: { SidebarItem, Logo }, data() { return { variables, }; }, computed: { ...mapState(["settings"]), ...mapGetters(["sidebarRouters", "sidebar"]), activeMenu() { const route = this.$route; if (route.meta?.activeMenu) return route.meta.activeMenu; return route.path; }, showLogo() { return this.$store.state.settings.sidebarLogo; }, isCollapse() { return !this.sidebar.opened; }, }, }; </script> <style lang="scss" scoped> $base-menu-item-height: 50px; $base-menu-margin: 6px 8px; $base-menu-border-radius: 12px; .logo-container { background: v-bind( "settings.sideTheme === &#39;theme-dark&#39; ? &#39;rgba(255,255,255,0.06)&#39; : &#39;#f5f5f5&#39;" ); border-bottom: v-bind( "settings.sideTheme === &#39;theme-dark&#39; ? &#39;1px solid rgba(255,255,255,0.1)&#39; : &#39;1px solid #ddd&#39;" ); } .sidebar-container { transition: width 0.3s, background-color 0.3s; height: 100%; overflow: hidden; box-shadow: 4px 0 16px rgba(0, 0, 0, 0.15); position: relative; z-index: 9; ::v-deep .scrollbar-wrapper { overflow-x: hidden !important; padding-right: 6px; // 垂直滚动条样式 - 暗色主题 .el-scrollbar__bar.is-vertical { right: 2px; opacity: 0.6; &-thumb { background-color: rgba(100, 150, 255, 0.4); border-radius: 4px; transition: background-color 0.3s ease; &:hover { background-color: #5d8bfb; } } } // 明色主题下更明显的滚动条 .theme-light & .el-scrollbar__bar.is-vertical { opacity: 0.8; &-thumb { background-color: #c8c9cc; } } } ::v-deep .el-menu { border: none; padding-top: 12px; .el-menu-item, .el-submenu__title { height: $base-menu-item-height !important; line-height: $base-menu-item-height !important; margin: $base-menu-margin; color: v-bind( &#39;settings.sideTheme === "theme-dark" ? variables.menuColor : variables.menuLightColor&#39; ); font-weight: 500; border-radius: $base-menu-border-radius; background: transparent; transition: all 0.3s cubic-bezier(0.25, 0.8, 0.5, 1); position: relative; overflow: hidden; padding-left: 20px !important; &:hover { transform: translateY(-2px) scale(1.01); box-shadow: 0 6px 18px rgba(42, 74, 128, 0.35); // 暗色主题:霓虹渐变 &[class*="theme-dark"] & { background: linear-gradient(90deg, #3a2d6d, #2a4a80) !important; color: #ffffff !important; } // 明色主题:柔和高亮 &[class*="theme-light"] & { background: #e8f4ff !important; color: #000 !important; } } &.is-active { color: #ffffff !important; &[class*="theme-dark"] & { background: linear-gradient(90deg, #3a2d6d, #2a4a80) !important; border: 1px solid #5d8bfb; box-shadow: 0 0 10px #5d8bfb, 0 0 20px rgba(93, 139, 251, 0.5); animation: pulse-glow 2.5s infinite alternate ease-in-out; } &[class*="theme-light"] & { background: #eff6ff !important; border-left: 3px solid #5d8bfb; font-weight: 600; } } } // 子菜单嵌套项 .nest-menu { .el-menu-item { padding-left: 50px !important; font-size: 13px; opacity: 0.9; &:hover { background: linear-gradient(90deg, #4a3a7d, #3a5a90) !important; } } } } } // 💫 脉冲发光动画(仅用于暗色主题) @keyframes pulse-glow { 0% { box-shadow: 0 0 10px #5d8bfb, 0 0 20px rgba(93, 139, 251, 0.5); } 100% { box-shadow: 0 0 16px #79a7ff, 0 0 32px rgba(93, 139, 251, 0.8), inset 0 0 8px rgba(255, 255, 255, 0.1); } } </style> 换个适合疗养院的主题
最新发布
09-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值