el-talbe 静态删除行数据

实现el-talbe动态添加行和静态多选删除行的功能,废话不多说直接上代码:

<template>
        <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="addInsideData"
            >添加</el-button
          >
          <el-button
            type="danger"
            icon="el-icon-remove"
            size="mini"
            @click="removeInsideData"
            >移除</el-button
          >
        <el-table
              :data="insideData"
              border
              style="width: 100%"
              size="mini"
            >
              <el-table-column type="selection" align="center" width="40" />
              <el-table-column
                type="index"
                label="序号"
                width="50"
                align="center"
              />

              <el-table-column prop="insideName" label="费用名称">
                <template slot-scope="scope">
                  <input
                    class="input_line2"
                    style="width: 99%"
                    v-model="scope.row.insideName"
                  />
                </template>
              </el-table-column>
              <el-table-column prop="insideMoney" label="金额" width="180">
                <template slot-scope="scope">
                  <input
                    class="input_line2"
                    style="width: 99%; text-align: right"
                    v-model="scope.row.insideMoney"
                    oninput="value=value.replace(/[^\d.]/g,'')"
                    @input="setBigMoney(scope.row)"
                  />
                </template>
              </el-table-column>
              <el-table-column prop="address" width="280" label="大写">
                <template slot-scope="scope">
                  <input
                    style="width: 99%; text-align: left; border: none"
                    v-model="scope.row.insideBigMoney"
                    readonly
                  />
                </template>
              </el-table-column>
            </el-table>
</template>
export default {
  name: "contract",
  data() {
    return {
        insideData:[],
        multipleInsideSelection:[]
    }
  },
  methods:{
    // 批量删除
    removeInsideData() {
      if (this.multipleInsideSelection.length > 0) {
        var ids = this.multipleInsideSelection.map((item) => item.indexNo);
        this.insideData = this.arrayAminusB(
          this.insideData,
          this.multipleInsideSelection
        );
      } else {
        this.$message.warning("请选择记录");
      }
    },
    arrayAminusB(arrA, arrB) {
      return arrA.filter((v) => !arrB.includes(v));
    },
    // 添加其中
    addInsideData() {
      let inside = {
        indexNo: this.insideData.length + 1,
        insideName: "",
        insideMoney: "",
        busYear: this.curYear,
      };
      this.insideData.push(inside);
    },
  }

}

总结:此示例完成非后台删除记录,而是通过前端js方法来实现多选删除动态添加的记录

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值