vue页面经典布局

一、 上中下

<template>
    <div class="layout" id="layout" ref="layout" :style="`width:${width}px;height:${height}px`">
        <div class="layout-header" :style="`width:${width}px;height:${headerHeight}px`"></div>
        <div class="layout-main" :style="`width:${width}px;height:${mainHeight}px`">
            <div class="layout-main-content">
                <div v-for="i in 100" :key="i">{{i}}</div>
            </div>
        </div>
        <div class="layout-footer" :style="`width:${width}px;height:${footerHeight}px`"></div>
    </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
@Component({
    components: {}
})
export default class Layout extends Vue {
    height = 0

    width = 0

    headerHeight = 60

    mainHeight = 0

    footerHeight = 10

    mounted() {
        this.$nextTick(() => {
            this.width = window.innerWidth
            this.height = window.innerHeight
            this.mainHeight =
                this.height - this.headerHeight - this.footerHeight
        })

        window.onresize = () => {
            return (() => {
                this.width = window.innerWidth
                this.height = window.innerHeight
                this.mainHeight =
                    this.height - this.headerHeight - this.footerHeight
            })()
        }
    }
}
</script>

<style lang="scss" scoped>
.layout {
    background: darkcyan;

    .layout-header {
        background: darkgoldenrod;
    }

    .layout-main {
        background: darkorchid;

        overflow-y: auto;
        white-space: nowrap;

        .layout-main-content {
            width: 100%;
            white-space: nowrap;
            // justify-content: flex-start;
            // display: flex;
            // align-items: center;
        }
    }

    .layout-footer {
        background: darkseagreen;
    }
}
</style>

  1. 可以直接设置header的高度
  2. 可以直接设置footer的高度
  3. main里面的内容写到content里面,进行滚动条滚动

二、 左 右(上中下)

<template>
    <div class="layout" id="layout" ref="layout" :style="`width:${width}px;height:${height}px`">
        <div class="layout-left" :style="`width:${leftWidth}px;height:${height}px`">
            <div class="layout-left-logo" :style="`width:${leftWidth}px;height:${headerHeight}px`"></div>
            <div class="layout-left-menu" :style="`width:${leftWidth}px;height:${mainHeight+footerHeight}px`"></div>
        </div>

        <div class="layout-right" :style="`width:${rightWidth}px;height:${height}px`">
            <div class="layout-header" :style="`width:${rightWidth}px;height:${headerHeight}px`"></div>
            <div class="layout-main" :style="`width:${rightWidth}px;height:${mainHeight}px`">
                <div class="layout-main-content">
                    <div v-for="i in 100" :key="i">{{i}}</div>
                </div>
            </div>
            <div class="layout-footer" :style="`width:${rightWidth}px;height:${footerHeight}px`"></div>
        </div>

    </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'

@Component({
    components: { }
})
export default class Layout extends Vue {
    height = 0

    width = 0

    leftWidth = 100

    rightWidth = 0

    headerHeight = 100

    mainHeight = 0

    footerHeight = 0

    mounted() {
        this.$nextTick(() => {
            this.width = window.innerWidth
            this.height = window.innerHeight
            this.mainHeight =
                this.height - this.headerHeight - this.footerHeight
            this.rightWidth = this.width - this.leftWidth
        })

        window.onresize = () => {
            return (() => {
                this.width = window.innerWidth
                this.height = window.innerHeight
                this.mainHeight =
                    this.height - this.headerHeight - this.footerHeight
                this.rightWidth = this.width - this.leftWidth
            })()
        }
    }
}
</script>

<style lang="scss" scoped>
.layout {
    background: darkcyan;
    display: flex;

    .layout-left {
        background: rgb(224, 123, 123);

        .layout-left-logo {
            background: rgb(107, 202, 150);
        }

        .layout-left-menu {
            background: rgb(107, 145, 202);
        }
    }

    .layout-right {
        background: rgb(200, 247, 114);

        .layout-header {
            background: darkgoldenrod;
        }

        .layout-main {
            background: darkorchid;

            overflow-y: auto;
            white-space: nowrap;

            .layout-main-content {
                width: 100%;
                white-space: nowrap;
                // justify-content: flex-start;
                // display: flex;
                // align-items: center;
            }
        }

        .layout-footer {
            background: darkseagreen;
        }
    }
}
</style>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文主要讲述页面布局样式方面涉及的知识点,更全面的对CSS相应的技术进行归类、整理、说明,没有特别详细的技术要点说...
    Joel_zh阅读 1,012评论 0 1
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,921评论 1 45
  • 为了提高工作效率,不在CSS布局上多次耗费时间,故记录此练习笔记。借鉴了大神【浪里行舟】的博客,文末有链接。 CS...
    月上秦少阅读 1,152评论 2 13
  • 前言 面试题是永远都准备不完的!!!!! 前端常见的一些问题 1.前端性能优化手段? 1. 尽可能使用雪碧图 2....
    六月_7300阅读 516评论 0 1
  • 前言 面试题是永远都准备不完的!!!!! 前端常见的一些问题 1.前端性能优化手段? 1. 尽可能使用雪碧图2. ...
    ZJ懒得写简书阅读 10,532评论 22 266