vue + element-ui 表格最后一行添加按钮-点击后表格添加一行数据

代码如下:

<template>
<div>
  <el-table
    ref="singleTable"
    :data="tableData"
    highlight-current-row
    @current-change="handleCurrentChange"
    style="width: 100%">
    <el-table-column
      type="index"
      width="50">
    </el-table-column>
    <el-table-column
      property="date"
      label="日期"
      width="120">
      <template slot-scope="scope">
        <el-input clearable v-model="scope.row.date" placeholder="请输入日期"></el-input>
      </template>
    </el-table-column>
    <el-table-column
      property="name"
      label="姓名"
      width="120">
      <template slot-scope="scope">
        <el-input clearable v-model="scope.row.name" placeholder="请输入姓名"></el-input>
      </template>
    </el-table-column>
    <el-table-column
      property="address"
      label="地址">
      <template slot-scope="scope">
        <el-input clearable v-model="scope.row.address" placeholder="请输入地址"></el-input>
      </template>
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">确定</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-button style="width:100%;height:50px;background:#fff;color:#000" icon="el-icon-plus" @click="add" type="primary">添加信息</el-button>
</div>
</template>
 
<script>
  export default {
    data() {
      return {
        //这里可以设置初始值
        obj:{
          date: '',
          name: '',
          address: ''
        },
        tableData: [{
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }],
        currentRow: null
      }
    },
    methods: {
      add(){
        this.tableData.push(JSON.parse(JSON.stringify(this.obj)))
      },
      setCurrent(row) {
        this.$refs.singleTable.setCurrentRow(row);
      },
      handleCurrentChange(val) {
        this.currentRow = val;
      }
    }
  }
</script>

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值