vue v-for输出表格结构

本文介绍如何使用v-for指令在Vue.js中动态生成表格结构。通过定义字段数组和数据数组,可以实现表头和内容行的循环展示。示例展示了如何绑定数据到表格单元格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

v-for输出表格结构

数据库结构如下:

原理: 两个数组 a, b,  数组a的值,是数组b的键(索引), 变量拼接(红色区域);

 

 

<table>
      <tr>
          <th v-for='item in columnList'>{{item.column_name}}</th> //表头循环表的字段
      </tr>
      <tr v-for='item in inforList'>
          <td v-for='it in columnList'>{{item[it.column_name]}}</td> //循环字段对应的值
      </tr>
 </table>
//数据结构模拟
new
Vue({ el: '#app', data: { columnList: ['userId', 'userName', 'userTel', 'userEmail', 'userMessage', 'inTime'], //字段 inforList: [{'userId': '2', 'userName': '大华', 'userTel': '12345678', 'userEmail': null, 'userMessage': '哈哈’,'inTime': '2017-10-17 17:07:03'},{...}] //值 }
    })

效果图:

 

转载于:https://www.cnblogs.com/wangyihong/p/7687803.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值