表格铺满-slot用法-增加一行&删除一行

表格铺满-slot用法

图例

在这里插入图片描述

格式

//添加列表按钮
<div style="display:inline;float: right;margin-top:15px">
    <el-button type="primary" @click="addLine">添加培训自查</el-button>
</div>


//表格
//  max-height="10000000000"  用于无分页
<el-table :data="tableData" style="width: 100%" max-height="10000000000">
        <!-- <el-table-column prop="zip" label="序号" width="120"></el-table-column> -->
    //用于移除时,序号
        <el-table-column fixed label="序号" width="50" align="center">
            
          <template scope="scope">
            <span>{{scope.$index + 1}}</span>
          </template>
        </el-table-column>

        <el-table-column prop="name" label="培训/自查     ">
          <template scope="scope">
            <el-input size="small" v-model="scope.row.name" placeholder="请输入培训/自查主题"></el-input>
          </template>

          <!-- <el-input v-model="inputA" placeholder="请输入培训/自查主题"></el-input> -->
        </el-table-column>

        <el-table-column prop="date" label="培训/自查时间">
          <template scope="scope">
            <el-date-picker v-model="scope.row.data" type="date" placeholder="选择日期"></el-date-picker>
          </template>
        </el-table-column>
        <!-- <el-table-column label="备注">
        <template>
          <el-input v-model="inputA" placeholder="请输入培训/自查主题"></el-input>
        </template>
        </el-table-column>-->
        <el-table-column prop="province" label="请输入培训/自查主题 ">
          <template scope="scope">
            <el-input size="small" v-model="scope.row.province" placeholder="请输入培训/自查主题"></el-input>
          </template>

          <!-- <el-input v-model="inputA" placeholder="请输入培训/自查主题"></el-input> -->
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
            //slot插槽用法
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="deleteRow(scope.$index, tableData)"
              type="text"
              size="small"
            >移除</el-button>
          </template>
        </el-table-column>
      </el-table>

注:

scope.row.province、scope.row.data、scope.row.name,都为表格中对应的列展示要绑定的数据

数据

  data() {
    return {
      // 1.4表格
      tableData: [
        {
          date: "",   //培训/自查日期
          name: "",    //培训自查
          province: "",   //培训自查主题
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 1,
        },
        {
          date: "",
          name: "",
          province: "",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 2,
        },
        {
          date: "",
          name: "",
          province: "",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 3,
        },
        {
          date: "",
          name: "",
          province: "",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 4,
        },
        {
          date: "",
          name: "",
          province: "",
          city: "",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 5,
        },
        {
          date: "",
          name: "",
          province: "",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 6,
        },
        {
          date: "",
          name: "",
          province: "",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 7,
        },
      ],
    };
  },


    methods: {
        //删除行数
        deleteRow(index, rows) {
          rows.splice(index, 1);
        },
        addLine() {
          //添加行数
          var newValue = {
            date: "",
            name: "",
            province: "",
            zip: "",
          };
          //添加新的行数
          this.tableData.push(newValue);
          this.zip = this.zip + 1;
        },
      },

样式

//表头背景颜色
/deep/.el-table th,
.el-table tr {
  background: rgba(244, 245, 247, 1);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值