Element UI 是一个基于 Vue 2 的组件库,其 Table 组件是数据展示的核心工具之一。本文将带你深入了解其功能与使用技巧!

💻 核心功能

  • 数据渲染:支持表格数据的动态加载与静态展示
  • 排序过滤:可对列进行升序/降序排序,支持自定义过滤条件
  • 分页控制:内置分页组件,支持页码跳转与每页条数调整
  • 自定义列模板:通过作用域插槽自定义单元格内容(如图标、按钮等)
  • 响应式设计:自动适配不同屏幕尺寸

📌 示例:Element UI Table 官方文档 提供了完整 API 说明

📊 使用示例

<template>
  <el-table :data="tableData" border style="width: 100%">
    <el-table-column prop="date" label="日期" width="180">
      <template slot-scope="scope">
        <span style="color: #409EFF">{{ scope.row.date }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="name" label="姓名" width="180">
      <template slot-scope="scope">
        <el-tag>{{ scope.row.name }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column prop="address" label="地址">
      <template slot-scope="scope">
        <span>{{ scope.row.address }}</span>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        { date: '2023-04-01', name: '张三', address: '北京市' },
        { date: '2023-04-02', name: '李四', address: '上海市' }
      ]
    };
  }
};
</script>

📌 图片展示

element_ui_table
表格_组件

❓ 常见问题

  1. 如何实现表格行点击事件?
    使用 @row-click 事件绑定自定义方法

  2. 支持哪些数据格式?
    JSON 数组,每个对象对应一行数据

  3. 如何导出表格数据?
    可结合 el-button 和第三方库(如 xlsx)实现

🚀 进一步学习:Element UI Table 高级用法