• Element UI 表格常用改造(表头添加注释、翻页连续序号【内含前端分页】)


    表头添加注释

    在这里插入图片描述
    实现原理:表头插槽

    <el-table-column prop="name" width="180">
      <template slot="header">
        <el-tooltip effect="dark" content="身份证上的姓名" placement="top">
          <span>姓名 <i class="el-icon-question">i> span>
        el-tooltip>
      template>
    el-table-column>
    

    完整范例代码:

    <template>
      <div style="padding: 60px">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="date" label="日期" width="180"> el-table-column>
          <el-table-column prop="name" width="180">
            <template slot="header">
              <el-tooltip effect="dark" content="身份证上的姓名" placement="top">
                <span>姓名 <i class="el-icon-question">i> span>
              el-tooltip>
            template>
          el-table-column>
          <el-table-column prop="address" label="地址"> el-table-column>
        el-table>
      div>
    template>
    
    <script>
    export default {
      data() {
        return {
          tableData: [
            {
              date: "2016-05-02",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1518 弄",
            },
            {
              date: "2016-05-04",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1517 弄",
            },
          ],
        };
      },
    };
    script>
    

    翻页连续序号

    在这里插入图片描述
    实现原理:序号列插槽,根据页码、每页大小和默认序号动态生成连续序号

     <el-table-column
       type="index"
       fixed
       label="序号"
       width="50px"
       align="center"
     >
       <template slot-scope="scope">
         {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
       template>
     el-table-column>
    

    完整范例代码:

    <template>
      <div style="padding: 30px">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column
            type="index"
            fixed
            label="序号"
            width="50px"
            align="center"
          >
            <template slot-scope="scope">
              {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
            template>
          el-table-column>
          <el-table-column align="center" prop="date" label="日期" width="180">
          el-table-column>
          <el-table-column align="center" prop="name" label="姓名" width="180">
          el-table-column>
          <el-table-column align="center" prop="address" label="地址">
          el-table-column>
        el-table>
        <div style="padding: 10px">
          <el-pagination
            @size-change="pageSizeChange"
            @current-change="currentPageChange"
            :current-page="currentPage"
            :page-sizes="[2, 3]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="data.length"
          >
          el-pagination>
        div>
      div>
    template>
    
    <script>
    export default {
      data() {
        return {
          currentPage: 1,
          pageSize: 2,
          tableData: [],
          data: [
            {
              date: "2016-05-02",
              name: "王小虎1",
              address: "上海市普陀区金沙江路 1518 弄",
            },
            {
              date: "2016-05-04",
              name: "王小虎2",
              address: "上海市普陀区金沙江路 1517 弄",
            },
            {
              date: "2016-05-02",
              name: "王小虎3",
              address: "上海市普陀区金沙江路 1518 弄",
            },
            {
              date: "2016-05-04",
              name: "王小虎4",
              address: "上海市普陀区金沙江路 1517 弄",
            },
            {
              date: "2016-05-02",
              name: "王小虎5",
              address: "上海市普陀区金沙江路 1518 弄",
            },
            {
              date: "2016-05-04",
              name: "王小虎6",
              address: "上海市普陀区金沙江路 1517 弄",
            },
            {
              date: "2016-05-02",
              name: "王小虎7",
              address: "上海市普陀区金沙江路 1518 弄",
            },
            {
              date: "2016-05-04",
              name: "王小虎8",
              address: "上海市普陀区金沙江路 1517 弄",
            },
            {
              date: "2016-05-02",
              name: "王小虎9",
              address: "上海市普陀区金沙江路 1518 弄",
            },
          ],
        };
      },
      mounted() {
        this.updateTableData();
      },
      methods: {
        pageSizeChange(newPageSize) {
          this.pageSize = newPageSize;
          this.updateTableData();
        },
        currentPageChange(newPage) {
          this.currentPage = newPage;
          this.updateTableData();
        },
        // 前端分页
        updateTableData() {
          this.tableData = this.data.slice(
            (this.currentPage - 1) * this.pageSize,
            this.pageSize * this.currentPage
          );
        },
      },
    };
    script>
    
  • 相关阅读:
    深入理解“字符编码模型”
    ImmunoChemistry艾美捷通用阻断ELISA阻断缓冲液说明书
    基于HTML和JavaScript的会议室预约管理系统
    十分钟就能写个xxl-job插件
    Base64编码
    NewStarCTF2023week2-Unserialize?
    离线数仓(7):数仓理论之数据仓库建模
    Vue中自定义事件
    学习笔记|秩相关分析|Spearman相关分析|Kendall相关分析|规范表达|《小白爱上SPSS》课程:SPSS第十九讲:秩相关分析怎么做?
    Python的高阶玩法:面向对象编程思路在SOA中的使用
  • 原文地址:https://blog.csdn.net/weixin_41192489/article/details/126978895