Layout.vue 2.4 KB
<script setup>
import Head from '@/components/head.vue'
import { ref } from 'vue'
import router from '@/router/index'
const list = ref([
  { id: 1, path: '/home', name: '首页' },
  { id: 2, path: '/', name: '课程' },
  { id: 3, path: '/note', name: '笔记' },
  { id: 4, path: '/news', name: '消息' },
  { id: 5, path: '/disk', name: '云盘' },
  { id: 6, path: '/address', name: '通讯录' },
  { id: 7, path: '/account', name: '账号管理' },
  { id: 8, path: '/manage', name: '班级管理' }
])
const activeIndex = ref(1)
const navigator = (path, id) => {
  router.push(path)
  console.log(id)
  activeIndex.value = id
}
</script>

<template>
  <div class="counter">
    <!-- 封住头部组件 -->
    <Head></Head>
    <div class="banner">
      <!-- 左边部分 -->
      <div class="left">
        <div class="pic">
          <img src="@/static/Avatar.png" alt="" />
        </div>
        <div class="name">XXX</div>
        <div class="cont">
          <div
            v-for="(item, index) in list"
            :key="item"
            @click="navigator(item.path, index)"
            :class="{ 'active': activeIndex === index, 'li': true }"
          >
            {{ item.name }}
          </div>
        </div>
        <div class="one"></div>
      </div>
      <!-- 右边二级路由 -->
      <div class="right">
        <!-- 这里是二级路由的出口 -->
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.counter {
  width: 100%;
  height: 100%;

  .banner {
    display: flex;

    .left {
      position: relative;
      margin: 40px 40px 0;
      width: 15%;
      background-color: #6170c3;
      color: #fff;
      border-radius: 18px 18px 0 0;
      .pic {
        margin: 0 auto;
        padding-top: 50px;
        width: 75px;
        height: 75px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
      .name {
        margin-top: 10px;
        text-align: center;
      }
      .cont {
        margin-top: 20px;
        .li {
          line-height: 50px;
          width: 100%;
          height: 50px;
          padding-left: 30px;
          box-sizing: border-box;
        }
        .active {
          background-color: #4d5cb6;
        }
      }
      .one {
        background-color: pink;
      }
    }
    .right {
      width: 75%;
      background-color: #f2f2f2;
    }
  }
}
</style>