You need to enable JavaScript to run this app. Vue2+Vuetify2的v-list列表项内能否实现网格双列布局?如何实现?
优惠活动
大模型
产品
解决方案
定价
更多

Vue2+Vuetify2的v-list列表项内能否实现网格双列布局?如何实现?

解决方案

完全可以在现有列表项内部直接用Vuetify自带的布局系统实现两列对齐效果,不需要重构现有外层结构,同时可以完美适配你后续的交互需求。

具体实现

你可以直接用Vuetify内置的栅格系统或者flex工具类实现,以下是两种可选方案:

方案1:栅格布局(适配性更强,适合后续扩展按钮等内容)

修改你的template中v-list-item-content部分的代码即可:

<template>
  <v-list dense>
    <template v-for="(item, index) in items">
      <v-list-item :key="item.r">
        <v-list-item-content class="font-weight-bold">
          <v-row no-gutters align="center">
            <!-- 数字列:固定宽度、右对齐 -->
            <v-col cols="2" class="text-right pr-2">
              {{ item.n }}
            </v-col>
            <!-- 文本列:占剩余宽度、左对齐 -->
            <v-col cols="10" class="text-left">
              {{ item.t }}
            </v-col>
          </v-row>
        </v-list-item-content>
      </v-list-item>
      <v-divider :key="index"></v-divider>
    </template>
  </v-list>
</template>

<script>
export default {
  name: "itemList",
  data() {
    return {
      items: this.$store.state.currentItems,
    };
  },
};
</script>

参数说明:

  • no-gutters:去掉栅格默认的左右边距,避免占用多余列表空间
  • align="center":让数字和文本在垂直方向居中对齐
  • cols属性可以根据你数字的长度调整,比如数字最长为3位可以改成cols="3",保证所有列表项的数字列宽度统一,自然实现全局对齐。

方案2:Flex工具类(代码更简洁,适合纯展示场景)

如果不需要太复杂的扩展,也可以直接用Vuetify的flex工具类替换原有的v-list-item-title内容:

<v-list-item-title class="d-flex">
  <span class="text-right w-12 pr-2">{{ item.n }}</span>
  <span class="flex-grow-1 text-left">{{ item.t }}</span>
</v-list-item-title>

其中w-12是Vuetify内置宽度类,对应3rem,你也可以自定义宽度类适配你的数字长度。

后续交互适配

这个布局完全可以兼容你提到的所有后续需求:

  • 滑动操作:直接给v-list-item外层套滑动组件即可,内部两列作为整体滑动,不需要修改布局结构
  • 可点击按钮:把数字、文本位置的纯文本替换为<v-btn text @click="触发方法名"这类扁平按钮即可,栅格/flex布局会自动适配按钮尺寸
  • 拖拽排序:引入Vue2适配版的拖拽组件,将现有的v-for逻辑包裹在拖拽组件内绑定items数组即可,内部列表项结构无需调整。

内容的提问来源于stack exchange,提问作者chmike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 14:42:00