vue+element-ui table表格的使用 编辑、删除以及分页

效果图

   <el-table :data="groupList" v-loading="loading">
      <el-table-column type="index" label="序号" align="center"></el-table-column>
      <el-table-column prop="code" label="分组编码" align="center"></el-table-column>
      <el-table-column prop="name" label="分组全称" align="center"></el-table-column>
      <el-table-column prop="mark" label="备注" align="center"  :show-overflow-tooltip="true" :formatter="formatEmpty">
      </el-table-column>
      <el-table-column label="操作" align="center" width="250">
        <template slot-scope="groupList">
          <el-button
            size="mini"
            class="config-btn"
            style="width:70px;"
            @click.native.prevent="editGroup(groupList.$index, groupList)"
          >编辑</el-button>
          <el-button
            class="blue-btn"
            size="mini"
            style="width:70px"
            @click.native.prevent="deleteGroup(groupList.$index, groupList.row.id)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>


    <div class="table-pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="page.total"
        :page-size="page.limit"
        @current-change="pageChange"
      ></el-pagination>
    </div


loading是加载动画 data是需要使用的表格  prop为表格下方的参数    show-overflow-tooltip文字过长显示省略号   :formatter 对表格的内容进行处理
  data() {
    return {
     // 选中表格index
      activeIndex: undefined,
      groupList: [],
      loading:false,
       //分页参数 一页有n条 当前页  总数
      page: {
        limit: undefined,
        p: undefined,
        total: undefined
      }
    };
  },
  methods:{
    //获取表格
    getGroup(params) {
      this.loading = true;
      getGroupTable(params)
        .then(response => {
          this.groupList = response.data;
           this.page = {
            total: response.count,
            limit: response.limit,
            p: response.p
          };
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    //分页
  pageChange(val) {
      this.queryParams.p = val;
      this.getGroup();
    },
       // 编辑
        editGroup(index, groupList) {
      this.activeIndex = index;
      //这样就不会共用同一个对象 避免对话框内容改变的时候遮罩下面跟着改变
      this.editGroupInfo = Object.assign({}, groupList.row);
      this.editGroupDialog = true;
    },

     // 删除
    deleteGroup(index, id) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let params = {
            id: id
          };
          deleteGroup(params, id).then(response => {
            this.groupList.splice(index, 1);
            this.$message({
              type: "success",
              message: "删除成功!"
            });
          });
        })
        .catch(() => {});
    },
     //空数据转化为‘-’
   formatMark(row) {
      console.log(row);
      return row.mark ? row.mark : "-";
    },

}

 

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值