二次封装elmentui表格和分页

Table.vue

<template>
  <div class="tables">
    <div class="tabelLists">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="编号" width="50" align="left" v-if="countFlag">
          <template slot-scope="scope">
            <div>{{scope.$index+1}}</div>
          </template>
        </el-table-column>
        <template v-for="(col,i) in cloumns">
          <el-table-column
            :prop="col.prop"
            :key="i"
            :label="col.label"
            :width="col.width"
            :show-overflow-tooltip="col.show"
          >
          </el-table-column>
        </template>
        <slot name="one"></slot>
        <slot name="operate"></slot>
      </el-table>
      <div class="pagenation" v-if="pageFlag">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          :pager-count="5"
          layout="prev, pager, next, total, jumper"
          :total="totalNum"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "dataTable",
  // props: ["tableData", "cloumns", "countFlag"],
  props: {
    tableData: {
      required: true,
      type: Array
    },
    cloumns: {
      required: true,
      type: Array
    },
    countFlag: {
      default: true
    },
    pageFlag: {
      default: false
    },
    currentPage:{
      default:1
    },
    pageSize:{
      default:10
    },
    totalNum:{
      default:0
    },
  },
  mounted() {},
  data() {
    return {};
  },
  methods: {
    handleCurrentChange(val) {
      this.$emit("handleCurrentChange", val);
    }
  }
};
</script>
<style lang="less" scoped>
.tables {
  .tabelLists {
    margin-top: 10px;
    .edit {
      color: #4880ff;
      cursor: pointer;
      padding: 0 3px;
    }
  }
  .pagenation {
    text-align: center;
    margin-top: 10px;
  }
}
</style>
<template>
  <div class="hostConfiguration">
    <Commons>
      <template>
        <Table
          :tableData="taskData"
          :cloumns="cloumns"
          :pageSize="pageSize"
          :currentPage="currentPage"
          :totalNum="totalNum"
          :pageFlag="true"
          @handleCurrentChange="handleCurrentChange"
        >
          <template slot="one">
            <el-table-column label="密码" prop="password" width="100">
              <template slot-scope="scope">
                <span>{{scope.row.password?"*******":""}}</span>
              </template>
            </el-table-column>
            <el-table-column label="秘钥" prop="secretKey" width="100">
              <template slot-scope="scope">
                <span>{{scope.row.secretKey ? "*****":""}}</span>
              </template>
            </el-table-column>
          </template>
          <template slot="operate">
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button type="text" @click="editAlarm(scope.row)">编辑</el-button>
                <el-button type="text" @click="delAlarm(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </template>
        </Table>
      </template>
    </Commons>
  </div>
</template>
<script>
import Commons from "../../../components/commons/commons.vue";
import Table from "@/components/commons/Table";
export default {
  name: "hostConfiguration",
  data() {
    return {
      taskData: [],
      currentPage: 1,
      pageSize: 10,
      totalNum: 0,
      cloumns: [
        { prop: "ip", label: "主机IP", show: true, width: 200 },
        { prop: "remarks", label: "备注", show: true, width: 300 },
        { prop: "userName", label: "用户名", show: true, width: 120 }
      ]
    };
  },
  mounted() {
  },
  components: {
    Commons,
    Table
  },
  methods: {
  getData(),
  searchAlarm(),
    handleCurrentChange(index) {
      this.currentPage = index;
      if (this.types == 1) {
        this.getData();
      }
      if (this.types == 2) {
        this.searchAlarm();
      }
    }
  }
};
</script>

你可能感兴趣的:(二次封装elmentui表格和分页)