—— 阿尔伯特·爱因斯坦

程序员の奇妙冒险

ElementUIElementUI
2025-04-09 11:21阅读:118评论:0

ElementUI 表格单元行列动态显示输入框

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
<div class="wagerTable">
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
prop="wagerCode"
label="下注号码">
</el-table-column>
<el-table-column prop="wagerAmount" label="下注金额">
<template slot-scope="scope">
<el-input
v-if="scope.row.editing"
v-model="scope.row.wagerAmount"
></el-input>
<span v-else>{{ scope.row.wagerAmount }}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="170px">
<template slot-scope="scope">
<el-button
v-if="scope.row.editing"
type="text"
@click="handleDefineCancel(scope.$index, scope.row)"
></el-button
>
<el-button
v-if="scope.row.editing"
type="text"
@click="handleEditCancel(scope.$index, scope.row)"
></el-button
>
<el-button
v-if="!scope.row.editing"
type="text"
@click="handleEditCancel(scope.$index, scope.row)"
></el-button
>
<el-button
v-if="!scope.row.editing"
type="text"
@click="delWagerTableRow(scope.$index, scope.row)"
></el-button
>
</template>
</el-table-column>
</el-table>
</div>
</template>
 
<style scoped>
 
</style>
 
<script>
export default {
data() {
return {
tableData: [{
wagerCode: 'X,4,3,X',
wagerAmount: '王小虎'
},{
wagerCode: 'X,4,3,X',
name: '王小虎'
},{
wagerCode: 'X,4,3,X',
name: '王小虎'
},{
wagerCode: 'X,4,3,X',
name: '王小虎'
},{
wagerCode: 'X,4,3,X',
name: '王小虎'
}]
}
},
methods: {
// 编辑 或取消
handleEditCancel(index, row) {
if (row.editing) {
this.$set(this.tableData[index], "editing", false);
} else {
this.$set(this.tableData[index], "editing", true);
}
},
// 保存表格行内编辑内容
handleDefineCancel(index, row) {
this.$set(this.tableData[index], "editing", false);
},
delWagerTableRow(index, item) {
this.$confirm("确定要移除【 " + item.wagerCode + " 】号码?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
this.tableData.splice(index, 1);
}).catch(() => {});
}
}
};
</script>
 
评论(0)
暂无评论来抢沙发吧~