vue3中element-plus表格搜索過濾數(shù)據(jù)
1、表格數(shù)據(jù)
// 表格數(shù)據(jù)
import type { User } from "@/interface";
const tableData = ref<User[]>([]);2、 表格搜索過濾數(shù)據(jù)
// 搜索內(nèi)容
const search = ref("");
// 表格過濾數(shù)據(jù)
const tableFilterData = computed(() =>
tableData.value.filter(
(data) => !search.value || data.moniker?.includes(search.value)
)
);
// 表格過濾數(shù)據(jù),等價代碼(分步拆解)
/*
const tableFilterData = computed(() => {
// 若 search 為空,直接返回原數(shù)組
if (search.value) return tableData.value;
// 否則過濾包含關(guān)鍵詞的項
return tableData.value.filter((data) => {
// 安全訪問 moniker,不存在則返回 undefined(過濾掉)
let moniker = data.moniker ?? "";
return moniker.includes(search.value);
});
});
*/3、表格引用搜索過濾數(shù)據(jù),:data="tableFilterData"
<el-table
:data="tableFilterData"
<el-table-column type="selection" header-align="center" />
<el-table-column prop="moniker" label="人員">
<template #header>
<el-input v-model="search" :prefix-icon="Search">
<template #prepend>人員</template>
</el-input>
</template>
</el-table-column>
</el-table>4、應(yīng)用效果


到此這篇關(guān)于vue3中element-plus表格搜索過濾數(shù)據(jù)的文章就介紹到這了,更多相關(guān)element-plus表格過濾內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
el-table 選擇框根據(jù)條件設(shè)置某項不可選中的操作代碼
這篇文章主要介紹了el-table 選擇框根據(jù)條件設(shè)置某項不可選中的操作代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-03-03
Vue使用vue-area-linkage實現(xiàn)地址三級聯(lián)動效果的示例
很多時候我們需要使用地址三級聯(lián)動,即省市區(qū)三級聯(lián)動,這篇文章主要介紹了Vue使用vue-area-linkage實現(xiàn)地址三級聯(lián)動效果的示例,感興趣的小伙伴們可以參考一下2018-06-06
vue3接口數(shù)據(jù)賦值對象,渲染報錯問題及解決
這篇文章主要介紹了vue3接口數(shù)據(jù)賦值對象,渲染報錯問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
如何解決element-ui中多個table在tab切換時出現(xiàn)寬度縮小問題
這篇文章主要介紹了如何解決element-ui中多個table在tab切換時出現(xiàn)寬度縮小問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10
vue3使用vuex實現(xiàn)頁面實時更新數(shù)據(jù)實例教程(setup)
在前端開發(fā)中往往會遇到頁面需要實時刷新數(shù)據(jù)的情況,給用戶最新的數(shù)據(jù)展示,這篇文章主要給大家介紹了關(guān)于vue3使用vuex實現(xiàn)頁面實時更新數(shù)據(jù)(setup)的相關(guān)資料,需要的朋友可以參考下2022-09-09

