前端vue实现表格的增删功能方法

 <div>
        <div>
          <el-form size="small">
            <el-row :gutter="10">
              <el-form-item>
                <template>
                  <el-table border :data="table" style="width: 800px">
                    <el-table-column prop="commodityName" type="text" label="货物名称">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.commodityName"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column prop="specificationModel" type="text" label="规格型号">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.specificationModel"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column prop="unit" type="text" label="单位">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.unit"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column prop="quantity" type="text" label="数量">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.quantity"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column prop="unitPrice" type="text" label="单价">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.unitPrice"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column prop="amount" type="text" label="金额">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.amount"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作">
                      <template slot-scope="scope">
                        <el-button @click.native.prevent="deleteRow(scope.$index, table)" size="small"> 移除
                        </el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </template>
              </el-form-item>
              <el-button type="primary" @click="addRow(table)">新增</el-button>
            </el-row>
          </el-form>
        </div>

 

deleteRow(index, rows) {//删除改行
      rows.splice(index, 1);
    },
    // 表格新增
    addRow(table, event) {
      table.push({
        commodityName: '', specificationModel: '',unit: '',quantity: ''
        ,unitPrice: '',amount: ''
      })
      console.log("alldata",table)
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值