You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Vue.js中如何展示含数组属性的对象并匹配指定列表结构?

Vue.js 实现对象嵌套数组渲染列表方案

实现思路

你需要用双层v-for指令完成渲染:

  • 第一层v-for遍历JSON对象,拿到每个键名和对应的数组值
  • 第二层v-for遍历数组,渲染每个列表项

完整代码示例

选项式API(Vue2/Vue3通用)

<template>
  <!-- 外层遍历JSON对象,value是数组,key是对象的键 -->
  <div v-for="(timeArr, groupKey) in timeGroup" :key="groupKey">
    <h1>{{ groupKey }}</h1>
    <ul>
      <!-- 内层遍历数组渲染每个li -->
      <li v-for="timeItem in timeArr" :key="timeItem">
        {{ timeItem }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 你的JSON对象存到响应式数据里
      timeGroup: {
        "1": [
          "15-16",
          "16-17",
          "17-18",
          "18-19"
        ],
        "2": [
          "15-16",
          "16-17",
          "17-18",
          "18-19"
        ]
      }
    }
  }
}
</script>

组合式API(Vue3

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 00:15:09