当前位置:首页 > VUE

vue实现上下分栏

2026-02-19 17:27:20VUE

Vue 实现上下分栏布局

上下分栏布局通常指将页面垂直划分为两个部分,可以通过以下方法实现:

方法一:使用 CSS Flexbox 布局

vue实现上下分栏

<template>
  <div class="container">
    <div class="top-section">顶部内容区域</div>
    <div class="bottom-section">底部内容区域</div>
  </div>
</template>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.top-section {
  flex: 1;
  background-color: #f0f0f0;
}
.bottom-section {
  flex: 1;
  background-color: #e0e0e0;
}
</style>

方法二:使用 CSS Grid 布局

vue实现上下分栏

<template>
  <div class="grid-container">
    <div class="header">头部区域</div>
    <div class="content">主要内容区域</div>
  </div>
</template>

<style scoped>
.grid-container {
  display: grid;
  grid-template-rows: 100px 1fr;
  height: 100vh;
}
.header {
  background-color: #ddd;
}
.content {
  background-color: #eee;
}
</style>

方法三:使用百分比高度

<template>
  <div>
    <div style="height: 30%; background: #f5f5f5;">上部分</div>
    <div style="height: 70%; background: #e5e5e5;">下部分</div>
  </div>
</template>

方法四:使用 Vue 组件实现可调整分栏

<template>
  <div class="resizable-container">
    <div 
      class="top-panel" 
      :style="{ height: topHeight + 'px' }"
    >
      可调整的顶部面板
    </div>
    <div class="divider" @mousedown="startResize"></div>
    <div class="bottom-panel">
      底部面板
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      topHeight: 200,
      isResizing: false
    }
  },
  methods: {
    startResize(e) {
      this.isResizing = true
      document.addEventListener('mousemove', this.resize)
      document.addEventListener('mouseup', this.stopResize)
    },
    resize(e) {
      if (!this.isResizing) return
      this.topHeight = e.clientY
    },
    stopResize() {
      this.isResizing = false
      document.removeEventListener('mousemove', this.resize)
    }
  }
}
</script>

<style scoped>
.resizable-container {
  height: 100vh;
  position: relative;
}
.top-panel {
  background: #f0f0f0;
  overflow: auto;
}
.bottom-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  top: 200px;
  background: #e0e0e0;
}
.divider {
  height: 5px;
  background: #ccc;
  cursor: row-resize;
}
</style>

注意事项

  • 确保父容器有明确的高度设置,否则分栏可能无法正确显示
  • 考虑添加 overflow 属性处理内容溢出的情况
  • 响应式设计可以通过媒体查询调整分栏比例
  • 复杂场景可考虑使用第三方布局库如 Split.js

以上方法可根据具体需求选择使用,Flexbox 和 Grid 方案较为现代且推荐使用,百分比方案简单直接,可调整分栏方案提供更好的用户体验。

标签: 上下vue
分享给朋友:

相关文章

vue实现通知

vue实现通知

Vue 实现通知功能的方法 使用 Vue 实现通知功能可以通过多种方式实现,以下是一些常见的方法: 使用 Vue 的全局事件总线 在 Vue 中可以通过事件总线实现通知功能。创建一个全局事件总线,然…

vue实现签章

vue实现签章

Vue 实现签章功能 签章功能通常包括手写签名、电子印章等。以下是基于 Vue 的实现方法: 使用 canvas 实现手写签名 安装依赖(如需要): npm install signatu…

vue实现vnc

vue实现vnc

Vue 实现 VNC 客户端 在 Vue 项目中实现 VNC 客户端功能,可以通过集成现有的 VNC 客户端库或组件完成。以下是具体实现方法: 安装依赖库 使用 noVNC 或其他 VNC 客户端…

vue 实现筛选

vue 实现筛选

实现筛选功能的基本方法 在Vue中实现筛选功能通常涉及以下几个核心步骤: 数据绑定与筛选逻辑 使用v-model绑定筛选条件到Vue实例的数据属性,结合计算属性实现动态筛选: data() {…

vue实现flvvideo

vue实现flvvideo

vue-flv-player 实现 FLV 视频播放 安装依赖包 npm install flv.js vue-flv-player 基础组件引入 <template> <v…

vue实现ssr

vue实现ssr

Vue 实现 SSR(服务端渲染) Vue 的服务端渲染(SSR)允许在服务器端生成完整的 HTML 内容,再发送到客户端,提升首屏加载速度和 SEO 友好性。以下是实现 Vue SSR 的关键步骤和…