VUE?el-table列表搜索功能純前端實(shí)現(xiàn)方法
背景:
對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: '請輸入要搜索的內(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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解如何將 Vue-cli 改造成支持多頁面的 history 模式
本篇文章主要介紹了詳解如何將 Vue-cli 改造成支持多頁面的 history 模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11
vue一步到位的實(shí)現(xiàn)動(dòng)態(tài)路由
這篇文章主要介紹了vue一步到位的實(shí)現(xiàn)動(dòng)態(tài)路由,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06
基于vue-cli3創(chuàng)建libs庫的實(shí)現(xiàn)方法
這篇文章主要介紹了基于vue-cli3創(chuàng)建libs庫的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
vue單頁面實(shí)現(xiàn)當(dāng)前頁面刷新或跳轉(zhuǎn)時(shí)提示保存
這篇文章主要介紹了vue單頁面實(shí)現(xiàn)當(dāng)前頁面刷新或跳轉(zhuǎn)時(shí)提示保存,在當(dāng)前頁面刷新或跳轉(zhuǎn)時(shí)提示保存并可取消刷新,以防止填寫的表單內(nèi)容丟失,感興趣的小伙伴們可以參考一下2018-11-11
Vue2?與?Vue3?的數(shù)據(jù)綁定原理及實(shí)現(xiàn)
這篇文章主要介紹了Vue2與Vue3的數(shù)據(jù)綁定原理及實(shí)現(xiàn),數(shù)據(jù)綁定是一種把用戶界面元素的屬性綁定到特定對象上面并使其同步的機(jī)制,使開發(fā)人員免于編寫同步視圖模型和視圖的邏輯2022-09-09
Vue+Element ui 根據(jù)后臺返回?cái)?shù)據(jù)設(shè)置動(dòng)態(tài)表頭操作
這篇文章主要介紹了Vue+Element ui 根據(jù)后臺返回?cái)?shù)據(jù)設(shè)置動(dòng)態(tài)表頭操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
vue項(xiàng)目動(dòng)態(tài)設(shè)置頁面title及是否緩存頁面的問題
這篇文章主要介紹了vue項(xiàng)目動(dòng)態(tài)設(shè)置頁面title及是否緩存頁面的問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-11-11
解決vue打包后刷新頁面報(bào)錯(cuò):Unexpected token <
這篇文章主要介紹了解決vue打包后刷新頁面報(bào)錯(cuò):Unexpected token <相關(guān)知識點(diǎn),需要的朋友們參考下。2019-08-08

