uni-app封装表格组件

组件代码:

<template>
  <view>
    <uni-table class="tableBox" border stripe emptyText="暂无更多数据" >
      <!-- 表头行 -->
      <uni-tr class="tableTr">
        <uni-th align="center" v-for="item in tableDataCloums">{
  {item.title}}</uni-th>
      </uni-tr>
      <!-- 表格数据行 -->
      <uni-tr v-for="(el,index) in tableDataList">
        <uni-td align="center" v-if="item.prop !== 'operation'" v-for="item in tableDataCloums">{
  {getData(item,el,index)}}</uni-td>
        <uni-td align="center" v-else>
          <view class="btnBox">
            <u-button v-for="operationItem in getData(item,el,index)" @click="operationItemClick(operationItem,el)" :type="operationItem.type" :text="operationItem.text"></u-button>
          </view>
        </uni-td>
      </uni-tr>
    </uni-table>
    <!--分页-->
    <view class="pages">
      <u-button type="primary" @click="pageChange('pre')">{
  {'<'+'上一页'}}</u-button>
      <u-button type="primary" @click="pageChange('next')">{
  {'下一页'+'>'}}</u-button>
    </view>
  </view>
</template>
<script>
export default {
  props:{
    tableDataCloums:{
      type:Array,
      default:[]
    },
    tableDataList:{
      type:Array,
      default:[]
    }
  },
  methods: {
    pageChange(type){
      this.$emit('pageNumChange',type)
    },
    operationItemClick(operationItem,el){
      this.$emit(operationItem.fun,el)
    },
    getData(item,el,index){
      if(item.prop == 'operation'){
        return item.operation
      }
      return el[item.prop]
    }
  },
}
</script>
<style lang="scss" scoped>
.pages{
  display: flex;
  justify-content: center;
  padding: torpx(30);
  .u-button{
    margin: torpx(30);
    width: 30%;
  }
}
.table--border{
  border: none;
}
.tableTr{
  background: #DAE3F5;
}
.uni-table-th{
  font-size: torpx(24);
  color: #212121;
}
.uni-table-td{
  font-size: torpx(20);
}
.btnBox{
  display: flex;
  .u-button{
    margin: 0 torpx(10);
  }
}
</style>

组件使用代码:

const tableDataCloums = [
  {title:'会员卡编号',prop:'id'},
  {title:'会员电话',prop:'phone'},
  {title:'会员等级',prop:'vipGrade'},
  {title:'会员昵称',prop:'nickName'},
  {title:'当前积分',prop:'pointsCurrent'},
  {title:'等级权益',prop:'pointsCurrent'},
  {title:'余额',prop:'pointsCurrent'},
  {title:'开卡时间',prop:'createTime'},
  {title:'最近下单',prop:'updateTime'},
  {title:'操作',
    prop:'operation',
    operation:[
      {text:'充值',fun:'recharge',type:'primary'},
      {text:'充值记录',fun:'record',type:'warning'}
    ]
  },
]

<comsTable :tableDataCloums="balanceTableDataCloums" :tableDataList="balanceTableDataList"></comsTable>

页面样子:

相关推荐

  1. uni-app 倒计时组件

    2023-12-26 12:10:04       29 阅读
  2. uni-app怎样使用组件

    2023-12-26 12:10:04       27 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-26 12:10:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-26 12:10:04       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-26 12:10:04       82 阅读
  4. Python语言-面向对象

    2023-12-26 12:10:04       91 阅读

热门阅读

  1. uniapp中使用axios、uniapp中封装axios

    2023-12-26 12:10:04       57 阅读
  2. 算法训练营Day24

    2023-12-26 12:10:04       62 阅读
  3. ES6之数组新增的扩展

    2023-12-26 12:10:04       62 阅读
  4. ES6-11

    ES6-11

    2023-12-26 12:10:04      43 阅读
  5. 第38节: Vue3 鼠标按钮修改器

    2023-12-26 12:10:04       60 阅读
  6. django的通知和信号量

    2023-12-26 12:10:04       62 阅读
  7. day27 回溯(03)

    2023-12-26 12:10:04       69 阅读
  8. python 1200例——【9】斐波那契数列

    2023-12-26 12:10:04       56 阅读
  9. PHP中include 和 require 语句

    2023-12-26 12:10:04       57 阅读