vue element 表格的动态增减表格行

html:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<el-table size="mini" :data="eventSetings">
<el-table-column label="消费金额">
<template slot-scope="scope">
<el-input v-model="scope.row.money" size="mini" />
</template>
</el-table-column>
<el-table-column label="减免金额">
<template slot-scope="scope">
<el-input v-model="scope.row.reduce" size="mini" />
</template>
</el-table-column>
<el-table-column align="right">
<template slot="header" slot-scope="scope">
<el-button type="primary" @click="addEventSet">添 加</el-button>
</template>
<template slot-scope="scope">
<el-button
size="mini"
type="danger"
@click="deleteEventSet(scope.$index, scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>

js:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 数据部分
eventSetings: [
{
money: "",
reduce: "",
},
]





// 逻辑部分
// 添加
addEventSet() {
this.eventSetings.push({
money: "",
reduce: "",
});
},
// 删除
deleteEventSet(index, data) {
console.log(index, data);
this.eventSetings.splice(index, 1);
},

vue element 表格的动态增减表格行
https://github.com/chergn/chergn.github.io/41127977ecc7/
作者
全易
发布于
2024年3月28日
许可协议