vue中自定义table表格

​
<template>
<div>
<tableclass="table">
<thead>
<tr>
<th>序号</th>
<th>商品名称</th>
<th>商品分类</th>
<th>销售数量</th>
<th>商品价格</th>
</tr>
</thead>
<tbody>
<trv-for="(user,index) in stu">
<td>{
  {index+1}}</td>
<td>{
  {user.name}}</td>
<td>{
  {user.type}}</td>
<td>{
  {user.num}}</td>
<td>{
  {user.price}}</td>
</tr>
</tbody>
</table><
/div>
</template>​

​
export default{
data() {
  return {
    user:{name:'',type:'',num:'',price:''},
    stu:[
      {'name': '行情数据', 'type': 17,'num':6,'price':'¥30'},
      {'name': '行情数据', 'type'
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的示例代码,可以帮助你自定义一个表格组件: ```vue <template> <table> <thead> <tr> <th v-for="header in headers" :key="header">{{ header }}</th> </tr> </thead> <tbody> <tr v-for="(row, index) in rows" :key="index"> <td v-for="(item, key) in row" :key="key">{{ item }}</td> </tr> </tbody> </table> </template> <script> export default { props: { headers: { type: Array, required: true }, rows: { type: Array, required: true } } } </script> ``` 在这个组件,我们使用了两个 props:headers 和 rows。headers 表示表格的表头,是一个字符串数组;rows 表示表格的数据行,是一个对象数组。在组件的模板,我们使用了 v-for 指令来渲染表头和数据行。在表头,我们使用了 v-for 和 :key 指令来循环渲染表头的每一个单元格。在数据行,我们使用了 v-for 和 :key 指令来循环渲染每一行的每一个单元格。 你可以在父组件使用这个组件来渲染一个自定义表格: ```vue <template> <div> <my-table :headers="headers" :rows="rows"></my-table> </div> </template> <script> import MyTable from './MyTable.vue' export default { components: { MyTable }, data () { return { headers: ['Name', 'Age', 'Gender'], rows: [ { name: 'Alice', age: 25, gender: 'Female' }, { name: 'Bob', age: 30, gender: 'Male' }, { name: 'Charlie', age: 20, gender: 'Male' } ] } } } </script> ``` 在这个父组件,我们通过调用 MyTable 组件,并传入 headers 和 rows 两个 props 来渲染一个自定义表格。注意,父组件的数据格式必须符合 MyTable 组件 props 的要求,即 headers 必须是一个字符串数组,rows 必须是一个对象数组。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值