eltable数据脱敏
时间: 2023-11-07 13:54:48 浏览: 44
el-table数据脱敏可以通过使用作用域插槽来实现。在el-table-column中,我们可以通过scope.row来获取每一行的数据,然后根据需要进行脱敏处理。在你提供的代码中,可以看到使用了scope.row.receiverTel来获取电话号码进行展示。类似地,你可以添加更多的if-else语句来根据不同的字段进行展示脱敏后的数据。例如,你可以使用scope.row.email来获取邮箱地址,并在模板中进行脱敏展示。
相关问题
eltable单选获取数据
如果你想从一个表格中获取单选框的数据,可以使用以下代码:
```javascript
var radioButtons = document.getElementsByName('myRadioButton');
var selectedValue;
for (var i = 0; i < radioButtons.length; i++) {
if (radioButtons[i].checked) {
selectedValue = radioButtons[i].value;
break;
}
}
```
上述代码假设你的单选框的 name 属性为 'myRadioButton',并且每个单选框都有一个 value 属性。在循环中,我们检查每个单选框是否被选中。如果被选中,我们将其值存储在 selectedValue 变量中并中断循环。最后,selectedValue 将包含所选单选框的值。
eltable 展开折叠获取数据
为了实现el-table的展开折叠获取数据,可以通过以下步骤实现:
1.在el-table中添加expand属性,用于控制展开和折叠状态。
2.在el-table-column中添加type属性,用于指定列的类型,例如selection、index、expand等。
3.在el-table-column中添加slot-scope属性,用于指定列的作用域,例如header、default等。
4.在template中添加el-table-column的作用域插槽,用于自定义展开行的内容。
5.在methods中添加handleExpand方法,用于处理展开行的数据请求。
下面是一个示例代码:
```html
<template>
<el-table :data="tableData" style="width: 100%">
<el-table-column type="expand">
<template slot-scope="props">
<el-table :data="props.row.subData">
<el-table-column prop="name" label="Name"></el-table-column>
<el-table-column prop="age" label="Age"></el-table-column>
</el-table>
</template>
</el-table-column>
<el-table-column prop="name" label="Name"></el-table-column>
<el-table-column prop="age" label="Age"></el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{
name: 'John',
age: 18,
subData: []
},
{
name: 'Mike',
age: 22,
subData: []
}
]
}
},
methods: {
handleExpand(row, expandedRows) {
if (expandedRows.length > 1) {
expandedRows.shift();
}
if (row.subData.length === 0) {
// 发送请求获取子数据
// getSubData(row.id).then(res => {
// row.subData = res.data;
// });
}
}
}
}
</script>
```