vue构建dashboard

本文介绍了如何使用Vue来构建一个dashboard,通过三个步骤实现组件的水平和垂直划分,确保div铺满整个屏幕。首先,通过调整div布局解决边缘空白问题;接着,更新App.vue和index.html文件使得三个div完全占据屏幕;最后,进一步将组件垂直分为两层。完整源码可在GitHub上找到。

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

step1 水平划分组件为三层
<template>
  <div>
    <div class="upPart">
      a
    </div>
    <div class="centerPart">
      b
    </div>
    <div class="downPart">
      c
    </div>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
}
</script>

<style scoped>
.upPart{
  background-color:blanchedalmond;
}
.centerPart{
  background-color: aqua;
}
.downPart{
  background-color: blueviolet;
}
</style>

写了三个div会发现边缘还是有空白的,在index.html文件里加入如下代码即可解决
在这里插入图片描述

<style>
    html,body{
        margin: 0;
        padding: 0;
    }
</style>

效果如下
在这里插入图片描述

step2 使三个div铺满整个屏幕
<template>
  <div class="mainPage">
    <div class="upPart">
      a
    </div>
    <div class="centerPart">
      b
    </div>
    <div class="downPart">
      c
    </div>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
}
</script>

<style scoped>
html,body{
  height: 100%;
  width: 100%;
}
.mainPage{
  height: 100%;
  width: 100%;
}
.upPart{
  height: 30%;
  background-color:blanchedalmond;
}
.centerPart{
  height: 30%;
  background-color: aqua;
}
.downPart{
  height: 40%;
  background-color: blueviolet;
}
</style>

App.vue添加

#app{
  height: 100%;
  width: 100%;
}

index.html添加

html,body{
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}

效果如下
在这里插入图片描述

step3垂直划分组件为两层
<template>
  <div class="mainPage">
    <div class="upPart">
      a
    </div>
    <div class="centerPart">
      b
    </div>
    <div class="downPart">
      <div class="downPartLeft">
        c
      </div>
      <div class="downPartRight">
        d
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
}
</script>

<style scoped>
html,body{
  height: 100%;
  width: 100%;
}
.mainPage{
  height: 100%;
  width: 100%;
}
.upPart{
  height: 30%;
  background-color:blanchedalmond;
}
.centerPart{
  height: 30%;
  background-color: aqua;
}
.downPart{
  height: 40%;
  background-color: blueviolet;
}
.downPartLeft{
  width: 40%;
  /* 高度设置为父组件downPart的高度 */
  height: 40%;
  position: absolute;
  display: inline-block;
}
.downPartRight{
  width: 60%;
  height: 40%;
  background-color: coral;
  /* position设置为absolu可以进行left right top bottom等设置 */
  position: absolute;
  /* 重要 设置右边离屏幕右边距离为0 */
  right: 0%;
  display: inline-block;
}
</style>

在这里插入图片描述
源码地址:https://github.com/IcedOtaku/dashboard

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值