VUE?el-table列表搜索功能純前端實(shí)現(xiàn)方法
背景:
對(duì)el-table數(shù)據(jù)進(jìn)行搜索篩選,但是不想調(diào)取接口,純前端實(shí)現(xiàn)
直接看代碼:
<template> <div class="project-container"> <SearchInputVue :keyword.sync="keyword" :placeholder="placeholderWords" style="margin-bottom: 20px" /> <div class="table"> <DefectList :defect-list="keyword ? filterDefectList : defectList" :total="fetchListPageData.total" :on-page-change="pageChange" /> </div> </div> </template> <script lang="ts"> import Vue from 'vue' import SearchInputVue from '@/components/Input/SearchInput.vue' import DefectList from './components/DefectList.vue' // import Info from '@/mock.json' import API from '@/api' import { warn } from '@/utils/common' export default Vue.extend({ name: 'Index', components: { SearchInputVue, DefectList // TypeIcon }, data() { return { defectList: [], filterDefectList: [], placeholderWords: '搜索缺陷', keyword: '', fetchListPageData: { total: 0, page: 1, pageSize: 10 } } }, watch: { keyword(newVal) { const keyVal = newVal.replace(' ', '') this.filterDefectList = keyVal ? this.defectList.filter(item => item.title.includes(keyVal)) : this.defectList } }, created() { this.getDefectList() }, methods: { async getDefectList() { try { const res = await API.Defect.defectListData({ keyword: '', page: this.fetchListPageData.page, pageSize: this.fetchListPageData.pageSize }) this.defectList = res.data.list this.fetchListPageData.total = res.data.total } catch (error) { warn(error, true) } }, pageChange(current: number) { this.fetchListPageData.page = current this.getDefectList() } } }) </script> <style lang="stylus" scoped> .project-container { .project-name { img { position: relative; top: 3px; } } } </style>
searchInput.vue
<template> <el-input v-model="_keyword" :placeholder="placeholder" class="search" @change="$emit('trigger-event', _keyword)"> <img slot="prefix" class="search-icon" src="@/image/search.svg" alt="search" /> </el-input> </template> <script> export default { name: 'SearchInput', props: { placeholder: { type: String, default: '請(qǐng)輸入要搜索的內(nèi)容' }, keyword: { type: String, default: '' } }, computed: { _keyword: { set: function (val) { this.$emit('update:keyword', val) }, get: function () { return this.keyword } } } } </script> <style scoped lang="stylus"> .search { width: auto; /deep/ .el-input__prefix { margin-left: 10px; line-height: 40px; } /deep/ .el-input__inner { padding-left: 54px; width: 305px; // height: 56px; border-radius: 5px; background-color: rgba(34, 37, 41, 1); border: 0.5px solid rgba(255, 255, 255, 0.1); font-weight: normal; font-size: 16px; line-height: 32px; color: #fff; } /deep/ .el-input__suffix { .el-input__suffix-inner { border-color: none; position: relative; .el-icon-circle-close:before { content: '\e6db' !important; font-size: 24px; color: #387DFF; right: 20px; top: -7px; position: absolute; } } } } .search-icon { vertical-align: middle; line-height: 40px; } </style>
總結(jié)
到此這篇關(guān)于VUE el-table列表搜索功能純前端實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)VUE el-table列表搜索內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解如何將 Vue-cli 改造成支持多頁(yè)面的 history 模式
本篇文章主要介紹了詳解如何將 Vue-cli 改造成支持多頁(yè)面的 history 模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11vue一步到位的實(shí)現(xiàn)動(dòng)態(tài)路由
這篇文章主要介紹了vue一步到位的實(shí)現(xiàn)動(dòng)態(tài)路由,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06基于vue-cli3創(chuàng)建libs庫(kù)的實(shí)現(xiàn)方法
這篇文章主要介紹了基于vue-cli3創(chuàng)建libs庫(kù)的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12Vue3中解決組件間css層級(jí)問(wèn)題的最佳實(shí)踐
<Teleport> 是 Vue 3 中引入的一個(gè)內(nèi)置組件,用于將組件的內(nèi)容渲染到 DOM 中的指定位置,而不受組件層級(jí)結(jié)構(gòu)的限制,本文給大家介紹了Vue3使用Teleport解決組件間css層級(jí)問(wèn)題的最佳實(shí)踐,需要的朋友可以參考下2025-02-02vue單頁(yè)面實(shí)現(xiàn)當(dāng)前頁(yè)面刷新或跳轉(zhuǎn)時(shí)提示保存
這篇文章主要介紹了vue單頁(yè)面實(shí)現(xiàn)當(dāng)前頁(yè)面刷新或跳轉(zhuǎn)時(shí)提示保存,在當(dāng)前頁(yè)面刷新或跳轉(zhuǎn)時(shí)提示保存并可取消刷新,以防止填寫(xiě)的表單內(nèi)容丟失,感興趣的小伙伴們可以參考一下2018-11-11Vue2?與?Vue3?的數(shù)據(jù)綁定原理及實(shí)現(xiàn)
這篇文章主要介紹了Vue2與Vue3的數(shù)據(jù)綁定原理及實(shí)現(xiàn),數(shù)據(jù)綁定是一種把用戶界面元素的屬性綁定到特定對(duì)象上面并使其同步的機(jī)制,使開(kāi)發(fā)人員免于編寫(xiě)同步視圖模型和視圖的邏輯2022-09-09Vue+Element ui 根據(jù)后臺(tái)返回?cái)?shù)據(jù)設(shè)置動(dòng)態(tài)表頭操作
這篇文章主要介紹了Vue+Element ui 根據(jù)后臺(tái)返回?cái)?shù)據(jù)設(shè)置動(dòng)態(tài)表頭操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09vue項(xiàng)目動(dòng)態(tài)設(shè)置頁(yè)面title及是否緩存頁(yè)面的問(wèn)題
這篇文章主要介紹了vue項(xiàng)目動(dòng)態(tài)設(shè)置頁(yè)面title及是否緩存頁(yè)面的問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11解決vue打包后刷新頁(yè)面報(bào)錯(cuò):Unexpected token <
這篇文章主要介紹了解決vue打包后刷新頁(yè)面報(bào)錯(cuò):Unexpected token <相關(guān)知識(shí)點(diǎn),需要的朋友們參考下。2019-08-08