首页 > 其他分享 >vue前端table列表右侧的滑动条怎样实现

vue前端table列表右侧的滑动条怎样实现

时间:2023-09-10 11:01:32浏览次数:33  
标签:vue 滚动条 item scrollbar 滑动 webkit table overflow

要在Vue前端table列表右侧添加滑动条,您可以使用CSS overflow 属性和 ::-webkit-scrollbar 伪元素来实现。

以下是示例代码:

<template>
  <div class="table-container">
    <table class="table">
      <!-- 表头 -->
      <thead>
        <tr>
          <th>列名1</th>
          <th>列名2</th>
          <th>列名3</th>
          <!-- 添加更多的表头列... -->
        </tr>
      </thead>
      <!-- 表格内容 -->
      <tbody>
        <tr v-for="item in items" :key="item.id">
          <td>{{ item.column1 }}</td>
          <td>{{ item.column2 }}</td>
          <td>{{ item.column3 }}</td>
          <!-- 添加更多的数据列... -->
        </tr>
      </tbody>
    </table>
  </div>
</template>

<style>
.table-container {
  max-height: 300px; /* 设置容器最大高度 */
  overflow-y: auto; /* 启用垂直滚动条 */
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 10px;
  border: 1px solid #ccc;
}

/* 禁用水平滚动 */
.table-container::-webkit-scrollbar {
  display: none;
}
</style>

在上述示例中,将table包装在一个具有固定高度且设置了overflow-y: auto的容器中,当table的高度超过容器的高度时,会自动出现垂直滚动条。

另外,为了避免水平滚动条显示在列表区域中,我们使用了::-webkit-scrollbar伪元素并将其设置为不可见。

希望这个回答对您有所帮助!如果您还有其他问题,请随时提问。

标签:vue,滚动条,item,scrollbar,滑动,webkit,table,overflow
From: https://blog.51cto.com/u_16007699/7423902

相关文章

  • vue子组件获取父组件数据
    1、使用this.$parent.event直接调用//父组件<template><div><child></child></div></template><script>importchildfrom'~/components/dam/child';exportdefault{components:{child},......
  • AI绘画:StableDiffusion实操教程-诛仙-碧瑶(附高清图下载)
    前段时间我分享了StableDiffusion的非常完整的教程:“AI绘画:StableDiffusion终极宝典:从入门到精通”不久前,我与大家分享了StableDiffusion的全面教程:“AI绘画:StableDiffusion终极宝典:从入门到精通”。然而,仍有些读者提出,虽然他们已经成功地安装了此工具,但生成的作品与我展示......
  • vue3 如何获取格式为 proxy 值的原始值
    vue3中变量多使用ref,reactive来声明。如下:constfirstName=ref('Tom')constlastName=ref('Jerry')constform=reactive({name:'',sex:'',age:'',area:'',loves:[]})当想使用上面的数据时,如下://......
  • export ‘Vue‘ (imported as ‘Vue‘) was not found in ‘vue‘
    export'Vue'(importedas'Vue')wasnotfoundin'vue'(possibleexports:$computed,$fromRefs,$raw,$ref,BaseTransition,Comment,EffectScope,Fragment,KeepAlive,ReactiveEffect,Static,Suspense,Teleport,Text,Transit......
  • AI绘画:StableDiffusion实操教程-斗破苍穹-云韵-常服(附高清图下载)
    前段时间我分享了StableDiffusion的非常完整的教程:“AI绘画:StableDiffusion终极宝典:从入门到精通”不久前,我与大家分享了StableDiffusion的全面教程:“AI绘画:StableDiffusion终极宝典:从入门到精通”。然而,仍有些读者提出,虽然他们已经成功地安装了此工具,但生成的作品与我展示......
  • Vue进阶(幺陆陆):组件实例 $el 详解
    this指向组件实例,$el用于获取Vue实例挂载的DOM元素,在mounted生命周期中才有效,之前的钩子函数内无效。如下代码所示,Vue脚手架中,$el指向当前组件template模板中的根标签。<template><divid="root">Lorem,ipsum</div></template><script>exportdefault......
  • 从零开始使用vue2+element搭建后台管理系统(前期准备)
    准备开始1.安装node(node-v查询版本号)(下载地址:https://nodejs.org/en/download/)2. 安装淘宝镜像 npminstall-gcnpm--registry=https://registry.npm.taobao.org3.安装webpack,以全局的方式安装 npminstallwebpack-g4.全局安装vue以及脚手架vue-cli npminst......
  • 一套基于spring boot vue开发的UWB定位系统源码 UWB全套源码
    现代制造业厂区面积大、人员数量多、物资设备不断增加,随着工业信息化技术的发展,大型制造企业中对人员、车辆、物资的管理要求越来越细致。高精度定位管理系统使用UWB室内定位技术,通过在厂区安装定位基站,为人员或设备佩戴定位标签的形式,实现人员精准实时定位。可以实现人员、车辆物......
  • QTablewidget的使用 读写与遍历
    QTableWidget表格中的数据读写操作//读数据QStringstr=ui->TableWidget->item(row,column)->text();//取出字符串//item的参数row,column是行和列,都是从0开始,注意不要越界。intnum=str.toInt();//如果需要的是整型数,可以转成int//写数据ui->TableWidget->item(row,col......
  • vue.js:响应式布局([email protected])
    一,代码:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859<template>  <divclass="hello">    <div>页......