Vue-cli实战项目8 主布局的实现

本文档介绍了如何在Vue-cli项目中实现主布局,包括使用Element的Container布局容器,完成基本布局,设置全屏显示,实现左侧滚动以及滚动条美化。通过App.vue和layout.vue文件的代码展示,详细解释了整个过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上一章节

Vue-cli实战项目7 提交表单并且进行表单验证

主布局的实现

使用Element 的 Container 布局容器实现
在这里插入图片描述
Container 布局容器API

基本实现

添加布局组件

	 <el-container>
	  <el-header>Header</el-header>
	  <el-container>
		<el-aside width="200px">Aside</el-aside>
		<el-main>Main</el-main>
	  </el-container>
	</el-container>

相关样式

 .el-header{
    background-color: #B3C0D1;
    color: #333;
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
  }

初始效果
在这里插入图片描述
添加样式,使得布局占满全屏
在这里插入图片描述

左侧,实现滚动

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

美化滚动条

::-webkit-scrollbar-track
{
  background: rgba(0,0,0,.1);
  border-radius: 0;
}

::-webkit-scrollbar
{
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb
{
    cursor: pointer;
    border-radius: 5px;
    background: rgba(0,0,0,.25);
    transition: color .2s ease;
}

完整代码

App.vue

<template>
  <div id="app">
	 <router-view></router-view>
  </div>
</template>

<script>

export default {
  name: 'app',
  components: {
  },
  data () {
      return {
		radio: 6
      };
    }
}
</script>

<style>
::-webkit-scrollbar-track
{
  background: rgba(0,0,0,.1);
  border-radius: 0;
}

::-webkit-scrollbar
{
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb
{
    cursor: pointer;
    border-radius: 5px;
    background: rgba(0,0,0,.25);
    transition: color .2s ease;
}
</style>

layout.vue

<template>
	<div>
		<el-container style="position: absolute;left: 0;top: 0;bottom: 0;right: 0;overflow: hidden;">
		  <el-header>Header</el-header>
		  <el-container style="height: 100%;padding-bottom: 60px;">
			<!-- 侧边布局 -->
			<el-aside width="200px">
				<li v-for="i in 100" :key="i">{{i}}</li>
			</el-aside>
			<!-- 主布局 -->
			<el-main>
				<li v-for="i in 100" :key="i">{{i}}</li>
			</el-main>
		  </el-container>
		</el-container>
	</div>
</template>

<script>
</script>

<style>
	 .el-header{
	   background-color: #B3C0D1;
	   color: #333;
	 }
	 
	 .el-aside {
	   background-color: #D3DCE6;
	   color: #333;
	 }
	 
	 .el-main {
	   background-color: #E9EEF3;
	   color: #333;
	 }
</style>

下一章节

Vue-cli实战项目9 顶部导航栏的实现

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值