当前位置:   article > 正文

在Vue3 使用 element-plus 、 splitpanes 和 el-tab 把界面分成上下部分布局,并且支持 内容超过 进行滚动,且 滚动时候tabs的标题栏不会滚动

splitpanes

在做系统时候,我们经常需要使用到上下布局,最终需要的效果如下图:

 实现如上面效果,需要使用到开源组件 splitpanes ,地址:Splitpanes

 代码具体实现过程如下,先引用 组件

import { Splitpanes, Pane } from 'splitpanes'

import 'splitpanes/dist/splitpanes.css'

 接着写代码

  1. <splitpanes
  2. class="default-theme"
  3. horizontal
  4. style="height: 100%; padding: 10px 0px 0px; margin-bottom: 0px"
  5. >
  6. <pane :size="100 - paneSize">
  7. <el-tabs v-model="activeName" type="border-card" style="height: 100%; padding: 0px; margin-bottom: 0px; position: relative">
  8. <el-tab-pane label="测试信息" name="first" style="height: 100%; margin-bottom: 0px; position: relative">
  9. <el-card class="my-fill mt8" shadow="never" style="overflow: auto; height: 100%; padding: 2px 0px 60px">
  10. <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="120px" :inline="false" size="mini">
  11. <el-form-item label="Activity name" prop="name">
  12. <el-input v-model="ruleForm.name" />
  13. </el-form-item>
  14. <el-form-item label="Activity zone" prop="region">
  15. <el-select v-model="ruleForm.region" placeholder="Activity zone">
  16. <el-option label="Zone one" value="shanghai" />
  17. <el-option label="Zone two" value="beijing" />
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="Activity count" prop="count">
  21. <el-select-v2 v-model="ruleForm.count" placeholder="Activity count" :options="options" />
  22. </el-form-item>
  23. <el-form-item label="Activity time" required>
  24. <el-col :span="11">
  25. <el-form-item prop="date1">
  26. <el-date-picker v-model="ruleForm.date1" type="date" label="Pick a date" placeholder="Pick a date" style="width: 100%" />
  27. </el-form-item>
  28. </el-col>
  29. <el-col class="text-center" :span="2">
  30. <span class="text-gray-500">-</span>
  31. </el-col>
  32. <el-col :span="11">
  33. <el-form-item prop="date2">
  34. <el-time-picker v-model="ruleForm.date2" label="Pick a time" placeholder="Pick a time" style="width: 100%" />
  35. </el-form-item>
  36. </el-col>
  37. </el-form-item>
  38. <el-form-item label="Instant delivery" prop="delivery">
  39. <el-switch v-model="ruleForm.delivery" />
  40. </el-form-item>
  41. <el-form-item label="Activity type" prop="type">
  42. <el-checkbox-group v-model="ruleForm.type">
  43. <el-checkbox label="Online activities" name="type" />
  44. <el-checkbox label="Promotion activities" name="type" />
  45. <el-checkbox label="Offline activities" name="type" />
  46. <el-checkbox label="Simple brand exposure" name="type" />
  47. </el-checkbox-group>
  48. </el-form-item>
  49. <el-form-item label="Resources" prop="resource">
  50. <el-radio-group v-model="ruleForm.resource">
  51. <el-radio label="Sponsorship" />
  52. <el-radio label="Venue" />
  53. </el-radio-group>
  54. </el-form-item>
  55. <el-form-item label="Activity form" prop="desc">
  56. <el-input v-model="ruleForm.desc" type="textarea" />
  57. </el-form-item>
  58. <el-form-item label="Resources" prop="resource">
  59. <el-radio-group v-model="ruleForm.resource">
  60. <el-radio label="Sponsorship" />
  61. <el-radio label="Venue" />
  62. </el-radio-group>
  63. </el-form-item>
  64. <el-form-item label="Activity form" prop="desc">
  65. <el-input v-model="ruleForm.desc" type="textarea" />
  66. </el-form-item>
  67. <el-form-item label="Resources" prop="resource">
  68. <el-radio-group v-model="ruleForm.resource">
  69. <el-radio label="Sponsorship" />
  70. <el-radio label="Venue" />
  71. </el-radio-group>
  72. </el-form-item>
  73. <el-form-item label="Activity form" prop="desc">
  74. <el-input v-model="ruleForm.desc" type="textarea" />
  75. </el-form-item>
  76. <el-form-item label="Resources" prop="resource">
  77. <el-radio-group v-model="ruleForm.resource">
  78. <el-radio label="Sponsorship" />
  79. <el-radio label="Venue" />
  80. </el-radio-group>
  81. </el-form-item>
  82. <el-form-item label="Activity form" prop="desc">
  83. <el-input v-model="ruleForm.desc" type="textarea" />
  84. </el-form-item>
  85. <el-form-item label="测试 form" prop="desc">
  86. <el-input v-model="ruleForm.desc" type="textarea" />
  87. </el-form-item>
  88. </el-form>
  89. </el-card>
  90. </el-tab-pane>
  91. <el-tab-pane label="Config" name="second" style="overflow: auto; height: 100%; padding: 0px">Config</el-tab-pane>
  92. <el-tab-pane label="Role" name="third" style="overflow: auto; height: 100%; padding: 0px">Role</el-tab-pane>
  93. <el-tab-pane label="Task" name="fourth" style="overflow: auto; height: 100%; padding: 0px">Task</el-tab-pane>
  94. </el-tabs>
  95. </pane>
  96. <pane :size="paneSize">
  97. <el-tabs v-model="activeName" type="border-card" style="height: 100%; padding: 0px; margin-bottom: 0px; position: relative">
  98. <el-tab-pane label="测试信息" name="first" style="height: 100%; position: relative; position: relative">
  99. <el-card class="my-fill mt8" shadow="never" style="overflow: auto; height: 100%; padding: 2px 0px 100px">
  100. <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="120px" class="demo-ruleForm" :size="formSize" status-icon>
  101. <el-form-item label="Activity name" prop="name">
  102. <el-input v-model="ruleForm.name" />
  103. </el-form-item>
  104. <el-form-item label="Activity zone" prop="region">
  105. <el-select v-model="ruleForm.region" placeholder="Activity zone">
  106. <el-option label="Zone one" value="shanghai" />
  107. <el-option label="Zone two" value="beijing" />
  108. </el-select>
  109. </el-form-item>
  110. <el-form-item label="Activity count" prop="count">
  111. <el-select-v2 v-model="ruleForm.count" placeholder="Activity count" :options="options" />
  112. </el-form-item>
  113. <el-form-item label="Activity time" required>
  114. <el-col :span="11">
  115. <el-form-item prop="date1">
  116. <el-date-picker v-model="ruleForm.date1" type="date" label="Pick a date" placeholder="Pick a date" style="width: 100%" />
  117. </el-form-item>
  118. </el-col>
  119. <el-col class="text-center" :span="2">
  120. <span class="text-gray-500">-</span>
  121. </el-col>
  122. <el-col :span="11">
  123. <el-form-item prop="date2">
  124. <el-time-picker v-model="ruleForm.date2" label="Pick a time" placeholder="Pick a time" style="width: 100%" />
  125. </el-form-item>
  126. </el-col>
  127. </el-form-item>
  128. <el-form-item label="Instant delivery" prop="delivery">
  129. <el-switch v-model="ruleForm.delivery" />
  130. </el-form-item>
  131. <el-form-item label="Activity type" prop="type">
  132. <el-checkbox-group v-model="ruleForm.type">
  133. <el-checkbox label="Online activities" name="type" />
  134. <el-checkbox label="Promotion activities" name="type" />
  135. <el-checkbox label="Offline activities" name="type" />
  136. <el-checkbox label="Simple brand exposure" name="type" />
  137. </el-checkbox-group>
  138. </el-form-item>
  139. <el-form-item label="Resources" prop="resource">
  140. <el-radio-group v-model="ruleForm.resource">
  141. <el-radio label="Sponsorship" />
  142. <el-radio label="Venue" />
  143. </el-radio-group>
  144. </el-form-item>
  145. <el-form-item label="Activity form" prop="desc">
  146. <el-input v-model="ruleForm.desc" type="textarea" />
  147. </el-form-item>
  148. <el-form-item label="Resources" prop="resource">
  149. <el-radio-group v-model="ruleForm.resource">
  150. <el-radio label="Sponsorship" />
  151. <el-radio label="Venue" />
  152. </el-radio-group>
  153. </el-form-item>
  154. <el-form-item label="Activity form" prop="desc">
  155. <el-input v-model="ruleForm.desc" type="textarea" />
  156. </el-form-item>
  157. <el-form-item label="Resources" prop="resource">
  158. <el-radio-group v-model="ruleForm.resource">
  159. <el-radio label="Sponsorship" />
  160. <el-radio label="Venue" />
  161. </el-radio-group>
  162. </el-form-item>
  163. <el-form-item label="Activity form" prop="desc">
  164. <el-input v-model="ruleForm.desc" type="textarea" />
  165. </el-form-item>
  166. <el-form-item label="Resources" prop="resource">
  167. <el-radio-group v-model="ruleForm.resource">
  168. <el-radio label="Sponsorship" />
  169. <el-radio label="Venue" />
  170. </el-radio-group>
  171. </el-form-item>
  172. <el-form-item label="Activity form" prop="desc">
  173. <el-input v-model="ruleForm.desc" type="textarea" />
  174. </el-form-item>
  175. <el-form-item>
  176. <el-button type="primary" @click="submitForm(ruleFormRef)"> Create </el-button>
  177. <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
  178. </el-form-item>
  179. </el-form>
  180. </el-card>
  181. </el-tab-pane>
  182. <el-tab-pane label="Config" name="second" style="overflow: auto; height: 100%; padding: 0px">Config</el-tab-pane>
  183. <el-tab-pane label="Role" name="third" style="overflow: auto; height: 100%; padding: 0px">Role</el-tab-pane>
  184. <el-tab-pane label="Task" name="fourth" style="overflow: auto; height: 100%; padding: 0px">Task</el-tab-pane>
  185. </el-tabs>
  186. </pane>
  187. </splitpanes>

需要注意,上面滚动样式的时候,需要注意离底部距离需要有一定的高度,否则有部分内容会被遮挡看不见,我这里是设置成:padding: 2px 0px 60px  ,实际项目自己调整

重点,最后必须加上样式修改,否则滚动 的话,会连tabs的标题栏一样滚动,具体代码如下

  1. <style scoped lang="scss">
  2. //必须设置这样,否则滚动的话,会连tabs的标题栏一起滚动
  3. :deep(.el-tabs__content) {
  4. position: relative;
  5. height: 100%;
  6. padding: 0px;
  7. }
  8. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/76856
推荐阅读
相关标签
  

闽ICP备14008679号