上图为最终结果,我使用的是element-ui官方文档中的demo
官方文档中在data中添加了用于过滤的函数,对于我们自身的数据来说,添加了不会影响正常的数据显示。
<el-table :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))" style="width: 100%">
其中search是官方留出来让我们使用的一个参数,就是用于查找的参数。
所以根据需要绑定相应的input就可以
<el-input v-model="search"></el-input>
如果需要多数据进行模糊查询,就需要在el-tabel函数中按需添加自己需要查询的数据,我这里添加的是查询role参数,现在只支持查询string类型的数据,所以需要查询id的话建议在渲染时先把id修改为string类型的参数
<el-table
:data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase())||data.role.toLowerCase().includes(search.toLowerCase()))"
style="width: 100%"
@selection-change="handleSelectionChange"
>
该方法适用于setup语法糖。