ElementUI-Plus table is selected by default

ElementUI-Plus table is selected by default


Add: ref to table tag

<el-table :data="tableData" ref="tableRef">
    <!--Inside are the columns of the table--> Add to setup:
<\el-table>

setup(){     const tableRef = ref()     nextTick(() => {      tableData.value.forEach((row) => {      tableRef.value.toggleRowSelection(row, row.selected);    });    return {         tableRef     } } That is to say, there is a selected item in my tableData array , determine whether to select it based on this item.










The more tricky points are:

1. This.$nextTick is no longer available, but becomes a hook

2. Calling it in onUpdated never works, so I still call it in setup.

3.ref must be returned

4.Ref must add value, otherwise an error will be reported and no method can be found.

5. Obtaining tableRef requires delayed acquisition and cannot be obtained when the table has not been created.

6.row needs to use the original data of the table, tableData. If the row is traversed with the selected data, it will not be rendered.
——————————————— ———
Copyright statement: This article is an original article by CSDN blogger "HGGshiwo" and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement when reprinting.
Original link: https://blog.csdn.net/HGGshiwo/article/details/122850850

Guess you like

Origin blog.csdn.net/wwf1225/article/details/128871577