• 切換路由時更換成當前路由圖標


    
    <template>
      <div class="sidebar">
        <el-menu
          class="sidebar-el-menu"
          :default-active="onRoutes"
          :collapse="collapse"
          background-color="white"
          text-color="#A0A0A0"
          active-text-color="#32b16c"
          unique-opened
          router
        >
          <!-- system -->
          <div class="logo">
            <img src="../assets/images/logo.png" alt="logo" />
          </div>
          <div class="user">
            <div><img src="../assets/images/user.png" alt="user" /></div>
          </div>
    
          <template v-for="item in items">
            <template v-if="!item.route_only">
              <el-menu-item :index="item.index" :key="item.index">
                <img :class="'hide_' + item.index" :src="item.icon" alt="icon" />
                <img
                  :class="'show_' + item.index"
                  :src="item.icon_hover"
                  alt="icon"
                  style="display: none"
                />
                <span slot="title">{{ item.title }}</span>
              </el-menu-item>
            </template>
          </template>
    
          <!-- system -->
          <div class="system">
            <el-menu-item index="logout">
              <i class="el-icon-switch-button"></i>
              <span slot="title">退出登录</span>
            </el-menu-item>
          </div>
        </el-menu>
      </div>
    </template>
    
    <script>
    import bus from "../utils/bus";
    
    export default {
      data() {
        return {
          collapse: false,
          items: [
            {
              icon: require("../assets/images/speed.png"),
              icon_hover: require("../assets/images/speed_hover.png"),
              index: "speedup",
              title: "加速",
              route_only: false,
            },
            {
              icon: require("../assets/images/vip.png"),
              icon_hover: require("../assets/images/vip_hover.png"),
              index: "vip",
              title: "会员",
              route_only: false,
            },
            {
              icon: require("../assets/images/setting.png"),
              icon_hover: require("../assets/images/setting_hover.png"),
              index: "setting",
              title: "设置",
              route_only: false,
            },
            {
              icon: require("../assets/images/about.png"),
              icon_hover: require("../assets/images/about_hover.png"),
              index: "about",
              title: "关于",
              route_only: false,
            },
          ],
        };
      },
      computed: {
        onRoutes() {
          var route = this.$route.path.replace("/", "");
          setTimeout(() => {
            this.items.map((item) => {
              if (route === item.index) {
                document.querySelector(".hide_" + item.index).style.display =
                  "none";
                document.querySelector(".show_" + item.index).style.display =
                  "block";
              } else {
                document.querySelector(".hide_" + item.index).style.display =
                  "block";
                document.querySelector(".show_" + item.index).style.display =
                  "none";
              }
            });
          }, 0);
    
          return route;
        },
      }
    };
    </script>
    
    <style lang="less" scoped>
    .el-menu {
      /deep/ .el-menu-item {
        border-radius: 7px;
        margin: 0 4px;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 46px;
        margin: 16px 4px;
    
        span {
          margin-left: 7px;
          font-weight: bolder;
        }
      }
      /deep/ .el-menu-item:hover {
        background: #32b16c26 !important;
        color: #32b16c !important;
    
        img:nth-child(1) {
          display: none !important;
        }
        img:nth-child(2) {
          display: block !important;
        }
      }
    }
    
    .logo {
      font-size: 17px;
      font-weight: bolder;
      height: 68px;
      display: flex;
      justify-content: center;
      align-items: center;
    
      img {
        margin-right: 8px;
      }
    }
    .user {
      display: flex;
      justify-content: center;
      > div {
        display: flex;
        justify-content: center;
        align-items: center;
         40px;
        height: 40px;
        border-radius: 50%;
        background: #f4f4f4;
        img {
        }
      }
    }
    
    .sidebar {
      display: block;
      position: absolute;
      left: 0;
      top: 0px;
      bottom: 0;
      overflow-y: scroll;
      border-radius: 10px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    }
    
    .sidebar::-webkit-scrollbar {
       0;
    }
    .sidebar-el-menu:not(.el-menu--collapse) {
       160px;
      border-right: none;
    }
    .sidebar > ul {
      height: 100%;
      border-color: #191b1e;
    }
    .system {
       100%;
      position: absolute;
      bottom: 0;
    }
    </style>
    
    
    
  • 相关阅读:
    iscroll 使用及遇到的问题
    移动端web页面如何适配
    里面的div怎么撑开外面的div让高度自适应
    JavaScript 获取当前时间戳
    css样式 浏览器的读取顺序
    mouseover和mouseenter的区别
    【转】移动端input输入placeholder垂直不居中
    一张png图片 上面有多个图标,如何用CSS准确的知道其中某个图片的坐标
    JVM05——JVM类加载机制知多少
    【Java实用工具】——使用oshi获取主机信息
  • 原文地址:https://www.cnblogs.com/lbx6935/p/15234932.html
Copyright © 2020-2023  润新知