成功vue动态列实现

<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        prop="username"
        label="用户名"
        align="center"
        width="100px"
      ></el-table-column>
      <el-table-column v-for="col in cols" :key="col.name" :prop="col.name" :label="col.label">
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="100px">
        <template slot-scope="scope">
          <el-button
            type="info"
            icon="el-icon-message"
            @click="checkDetail(scope.row)"
            circle
          ></el-button>
          <el-button
            type="primary"
            icon="el-icon-edit"
            @click="modifyData(scope.row)"
            circle
          ></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            @click="deleteData(scope.row)"
            circle
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      layout="prev, pager, next, sizes, total, jumper"
      :page-sizes="[5, 10, 20, 100]"
      :page-size="pageSize"
      :total="list.length"
      :current-page.sync="currentPage"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      style="text-align: center; margin-top: 1%"
    ></el-pagination>
    <el-button type="text" @click="props()">弹页面</el-button>
  </div>
</template>

<script>
import { getList, remove } from "@/api/test";
export default {
  filters: {},
  data() {
    return {
      list: [],
      cols:[
        {name:'num1',label:'数量'},
        {name:'addtime',label:'添加日期'},
      ],
      listLoading: true,
      usernamef: "",
      pageSize: 20,
      currentPage: 1,
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    props() {
      window.open("/views/form/test_add", "_blank");
    },
    fetchData() {
      this.listLoading = true;
      let param = { username: this.usernamef };
      getList(param).then((response) => {
        this.list = response.Data;
        this.listLoading = false;
        this.currentPage = 1;
      });
    },
    deleteData(rowdata) {
      this.$alert("是否删除这条记录", "信息删除", {
        confirmButtonText: "确定",
        showCancelButton: true,
        callback: (action) => {
          var params = {
            id: rowdata.ID,
          };
          if (action == "cancel") return;
          remove(params).then((response) => {
            if (response.IsSuccess) {
              this.fetchData();
            }
            this.$message({
              type: "info",
              message: response.Message,
            });
          });
        },
      });
    },

modifyData(rowData) {
      this.$router.push("/patient/TEST/test_modify?id=" + rowData.ID);
    },
    checkDetail(rowData) {
      this.$router.push("/patient/TEST/test_detail?id=" + rowData.ID);
    },
    handleCurrentChange: function (cpage) {
      this.$data.currentPage = cpage;
    },
    handleSizeChange: function (psize) {
      this.$data.pageSize = psize;
    },
  },
};
</script>

关键代码:<el-table-column v-for="col in cols" :key="col.name" :prop="col.name" :label="col.label">

(0)

相关推荐