I really searched a lot of information online and found that I couldn't achieve the anti-selectThere is an example below
Then I went to check out the official website
I found that the official website has a method to teach you how to select a certain value. "Multiple choices“
Official website address
<template> <el-table ref="multipleTableRef" :data="tableData" style="width: 100%" @selection-change="handleSelectionChange" > <el-table-column type="selection" width="55" /> <el-table-column label="Date" width="120"> <template #default="scope">{{ }}</template> </el-table-column> <el-table-column property="name" label="Name" width="120" /> <el-table-column property="address" label="Address" /> </el-table> <div style="margin-top: 20px"> <el-button @click="toggleSelection([tableData[1], tableData[2]])"> Toggle selection status of second and third rows </el-button> <el-button @click="toggleSelection()">Clear selection</el-button> </div> </template> <script lang="ts" setup> import { ref } from 'vue' import { ElTable } from 'element-plus' interface User { date: string name: string address: string } const multipleTableRef = ref<InstanceType<typeof ElTable>>() const multipleSelection = ref<User[]>([]) const toggleSelection = (rows?: User[]) => { if (rows) { ((row) => { // TODO: improvement typing when refactor table // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error !.toggleRowSelection(row, undefined) }) } else { !.clearSelection() } } const handleSelectionChange = (val: User[]) => { = val } const tableData: User[] = [ { date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-08', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-06', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-07', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, ] </script>
Since there is a way to select a value on the official website
Isn't it easy to choose?
The following is the personal code
Step 1 Get the selected value and the unselected value
<el-table ref="multipleTableRef" :data="tableData" style="width: 100%" Bind toggle selected data @selection-change="handleSelectionChange" > </el-table> <div @click="invertSelection()" style="width: 114rem;height: 35rem;border: 1rem solid #9D9D9D;border-radius: 10rem;font-size: 15rem;color: #5C6170;display: flex;align-items: center;margin: 0 20rem;cursor: pointer;"> <img style="height: 15rem;margin: 0 10rem 0 15rem;" src="../../../assets/Select - Reverse Select @" alt="" srcset=""> <span>Reverse selection</span> </div> <script setup> let state = reactive({ peopleList:[],//Total data checkList: [],//Select the data array noCheckList:[],//The data array is not selected}) // Important Get selected unselected dataconst handleSelectionChange = (val) => { (val); = val const notIncludedArray = (item => !(item)); = notIncludedArray // (notIncludedArray); } const multipleTableRef= ref() // Multiple choice tableconst invertSelection = (rows) => { // rows requires selected data to be directly transferred to () //You need to unselect all first and then select the data that was just not selected if (rows) { ((row) => { (row, undefined) }) } else { () } } </script>
This is the end of this article about the implementation of the elementPuls form anti-selecting. For more related elementPuls form anti-selecting content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!