vue s-table与loadData使用

本文介绍了一种使用 loadData 方法从后台加载数据到表格的过程,并展示了如何通过 customRender 自定义单元格内容,包括日期格式化、违规时间范围显示及详细信息展示等高级功能。

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

一.loadData

1.loadData从后台加载数据
loadData: parameter => {
  Object.assign(this.queryParam, parameter)
  return getVersionList(this.queryParam).then(resp => {
    return resp.data
  })
},
//Object.assign(this.queryParam, parameter)注意此函数用法
2.loadData加载从上个页面携带过来的数据
tableData:[],
loadData: parameter => {
    return new Promise(resolve => {
      resolve(this.tableData)
    }).then(res => {
    return {records:res}
    //return res
  })
}
// 用tableData在show()中接到上个页面传递过来的数据

s-table

<s-table
    rowKey="id"
    :columns="columns"
    :data="loadData"
    class="cbcs-table cbcs-table-ellipsis"
    size="middle"
>
</s-table>    
              
// 主要注意customRender用法
columns: [
   {
     title: '序号',
     dataIndex: 'taxis',
     align: 'center',
     width: 60,
     customRender: function (text, record, index) {
       return (index + 1)
     }
   },
   {
     title: '版本号',
     dataIndex: 'version',
     align: 'center',
     width: 110
   },

  //调用函数
  {
     title: '违规时间',
     dataIndex: 'createTime',
     align: 'center',
  	 width: 100,
     customRender: (text) => this.$util.date.formatNumber(text, 'YYYY-MM-DD', false)
   },
   {
     title: '违规影响期',
     dataIndex: 'startTimeInt',
     align: 'center',
     width: 200,
     customRender: (text,record) => record.startTime +"-"+record.endTime
   },
   
   //点击事件
   {
     title: '详情',
     dataIndex: 'action',
     width: 80,
     align: 'center',
     fixed: 'right',
     scopedSlots: { customRender: 'action' }
   },
   // 页面上接收
    <a
     slot="action"
     slot-scope="text, record"
     href="javascript:void(0);"
     @click="preview(record)">详情</a>

  //调用函数,做更加详细的操作
  {
  	title: '说明',
    dataIndex: 'detail',
    customRender:(text,record)=>this.translateDetail(text,record)
  }
]//methods中定义函数translateDetail(text,record),做进一步操作
translateDetail(text,record){
      switch (record.problemType) {
        case "entry":
        //this.$options.filters['NumToUnitNum']在方法中调用的main.js中的过滤器NumToUnitNum
          text="中标项目"+record.bidName+",中标价格"+this.$options.filters['NumToUnitNum'](record.bidderBudgetMoney)+this.$options.filters['GetUnit'](record.bidderBudgetMoney)+",成交价为预算价的"+((record.bidderBudgetMoney/record.budgetMoney)*100).toFixed(2)+"%";
       break;
       ...
   }
   return text;
}       
   
    
   

### 关于 Vue 中 tree-table 组件的选择触发事件 在 Vue 生态系统中,`el-table` 是一个常用的表格组件库,支持树形结构的数据展示以及丰富的交互功能。对于 `tree-table` 的选择触发事件,通常涉及监听特定的行为并作出响应。 当处理带有树状结构的表格时,可以利用 `el-table` 提供的各种内置方法和属性来实现所需的功能。为了捕获选择变化的事件,可以通过设置 `@selection-change="handleSelectionChange"` 来定义自定义的方法 `handleSelectionChange` 处理逻辑[^4]。 下面是一个简单的例子,展示了如何配置 `el-table` 实现树表中的选择项改变后的回调函数: ```html <template> <div id="app"> <!-- 使用 :data 和 :row-key 属性绑定数据源 --> <el-table ref="multipleTable" :data="tableData" style="width: 100%" row-key="id" @selection-change="handleSelectionChange" border lazy :load="load" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="name" label="Name"></el-table-column> ... </el-table> {{ selectedRows }} </div> </template> <script> export default { data() { return { tableData: [ // 初始化一些测试数据... ], selectedRows: [] }; }, methods: { handleSelectionChange(selection) { this.selectedRows = selection; console.log('Current Selection:', selection); }, load(tree, treeNode, resolve) { setTimeout(() => { resolve([ { name: "child node", ... } ]); }, 1000); } } }; </script> ``` 在这个实例里,每当用户选择了不同的行或者取消选定时都会调用 `handleSelectionChange()` 方法,并更新视图上的已选项列表。此外还实现了懒加载子节点的功能以优化性能表现。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值