当前位置:   article > 正文

博客前端项目学习day03——框架页

博客前端项目学习day03——框架页
  1. 更新router,实现导航栏功能
    在这里插入图片描述
  2. 框架页分为多个部分,头部,头部包含logo以及用户信息,左端是导航栏,右端是导航栏对应的内容
    头部如下,
    在这里插入图片描述
    左端是导航栏如下,

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

框架页代码

<template>
  <div class="layout">
      <el-container >
  <el-header class="header">
    <div class="logo">Blog</div>
    <div class="user-info">
      <span>欢迎回来,</span>
      <el-dropdown trigger="click">
    <span class="nick-name">
     {{userInfo.nickName}}
      <span class="iconfont icon-close"></span>
    </span>
   
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item>个人信息</el-dropdown-item>
        <el-dropdown-item>退出</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
  <div class="avatar">
    <img :src="userInfo.avatar">
  </div>
  
  </div>
  </el-header>
  <el-container class="container">
    <el-aside width="200px"
              class="left-aside">
              <div>
                  <el-button class="post-btn">发布</el-button>
              </div>
              <div class="menu-panel">
              <ul>
                  <li v-for="(menu,index) in menuList" 
                      v-bind:key="menu">
                      <span class="menu-title-p" @click="openClose(index)">
                           <span :class="['iconfont',menu.icon]"></span>
                           <span class="menu-title">{{menu.title}}</span>
                           <span :class="['iconfont','open-close',menu.open?'icon-open':'icon-close']"></span>
                      </span>
                      
                  <ul class="sub-menu" 
                      v-show="menu.open">
                      <li v-for="subMenu in menu.children"
                          v-bind:key="subMenu">
                         <router-link :to="subMenu.path"
                                      :class="['sub-menu-item',activePath==subMenu.path?'active':'']"
                                      >
                                     {{subMenu.title}}
                         </router-link>
                      </li>
                </ul>
                  </li>
              </ul>
              </div>
              
              </el-aside>
    <el-main class="right-main">
      <router-view/>
    </el-main>
  </el-container>
</el-container>
  </div>
</template>

<script setup>
import {useRouter,useRoute} from 'vue-router'
import VueCookies from 'vue-cookies'
import {getCurrentInstance, ref,watch} from "vue"
import { ArrowDown } from '@element-plus/icons-vue'
const {proxy} = getCurrentInstance();
const router = useRouter();
const route = useRoute();
const menuList = ref([
  {
    title: "博客",
    icon: "icon-blog",
    open: true,
    children: [
      {
        title: "博客管理",
        path: "/blog/list",
      },
      {
        title: "分类管理",
        path: "/blog/category",
      },
    ],
  },
  {
    title: "专题",
    icon: "icon-zhuanti",
    open: true,
    children: [
      {
        title: "专题管理",
        path: "/special/list",
      },
    ],
  },
  {
    title: "设置",
    icon: "icon-settings",
    open: true,
    children: [
      {
        title: "个人信息设置",
        path: "/settings/my",
      },
      {
        title: "博客成员",
        path: "/settings/user",
      },
      {
        title: "系统设置",
        path: "/settings/sysInfo",
        roleType: 1,
      },
    ],
  },
  {
    title: "回收站",
    icon: "icon-delete",
    open: true,
    children: [
      {
        title: "回收站",
        path: "/recovery/list",
      },
    ],
  },
]);

const openClose =(index)=>{
    const open = menuList.value[index].open;
    menuList.value[index].open=!open;
}
const userInfo=ref({});
const init=()=>{
  userInfo.value=VueCookies.get("userInfo");
  userInfo.value.avatar = proxy.globalInfo.imageUrl
  +userInfo.value.avatar;
}
init();
const activePath = ref(null);
watch(route,(newVal,oldVal)=>{
  activePath.value=newVal.path;
},{immediate:true,deep:true});
</script>

<style lang="scss">
.layout{
  .header{
        border-bottom: 1px solid #ddd;
        display:flex;
        align-items: center;
        justify-content: space-between;
        .logo{
          font-size: 20px;
        }
        .user-info{
          display: flex;
          align-items: center;
          .nick-name{
            cursor: pointer;
            color:rgb(76, 187, 231);
            .icon-close{
            font-size:14px;
          }
          .avatar{
            margin-left: 10px;
            width:50px;
            border-radius: 25px;
            img{
              width:100%;
            }
          }
          }
        }
    }
    .container{
        padding-top:10px;
        background: #f5f6f7;
        height: calc(100vh - 60px);
        .left-aside{
           padding-left:15px;
           padding-right:15px;
           width:250px;
           .post-btn{
               background: green;
               color:#fff;
               height:40px;
               width:100%;
           }
           .menu-panel{
             margin-top:5px;
               ul,li{
                   padding: 0px;
                   margin: 0px;
                   list-style: none;
               }
               .menu-title-p{
                 padding:0px 5px;
                 line-height:40px;
                 cursor: pointer;
                   display: flex;
                   .iconfont{
                     font-size:18px;
                     color: #91949a;
                   }
                   .menu-title{
                     flex:1;
                     color: #3f4042;
                   margin-left: 5px;
               }
               .open-close{
                 font-size:16px;
                 width:20px;
               }
               }
               .menu-title-p:hover{
                 background: #ddd;
               }
               .sub-menu{
                 padding-left: 20px;
                 font-size: 14px;
                 .sub-menu-item{
                   padding:0px 10px;
                   display:block;
                   line-height: 30px;
                   text-decoration: none;
                   color:#3f4042;
                 }
                 .active{
                 }
                 .sub-menu-item:hover{
                 background: #ddd;
               }
               }
           }
        }
        .right-main{
           background: #fff;
        }
    }
}
</style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/857439
推荐阅读
相关标签
  

闽ICP备14008679号