<el-table-column prop="TEACHER_TYPE" label="教师类型" min-width="5">
<template #default="scope">
{
{scope.row.TEACHER_TYPE== 1 ? "数学老师" : scope.row.TEACHER_TYPE== 4 ? "英语老师" : "" }}
</template>
</el-table-column>
js gets the last object of the list collection
state.defaultSelected =state.VisLevel_Ary.slice(-1)[0];
After adding, select the new row in el-table
1. To achieve this, you need to query first after adding, and then add.
Omit the new part, after adding.
select().then(() => {
state.defaultSelected =state.VisLevel_Ary.slice(-1)[0];
rowClick(state.defaultSelected)
})
The following singleTable is ref="singleTable" bound by el-table
const rowClick = function(row){
setCurrent(row);
state.code= row.code;
state.name= row.name;
}
// 当前数据行背景样式
const setCurrent= function(row) {
_this.$refs.singleTable.setCurrentRow(row);
}
In this way, the newest row can be selected after adding. Of course, this requires no pagination. If there is pagination, this will not work. You have to judge how many items there are on a page, how many pages there are in total, and so on, so that it can be displayed One page must have this article of data, which is more troublesome, it is better not to do it.