vue+elementUI實(shí)現(xiàn)表格關(guān)鍵字篩選高亮
本文實(shí)例為大家分享了vue elementUI表格關(guān)鍵字篩選高亮的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
<template>
<div class="">
<div class="top">
<!-- 篩選 -->
<div class="screen">
<div style="width:30%">篩選:</div>
<el-input type="search" v-model="search" style="width:70%" placeholder="請(qǐng)輸入關(guān)鍵字"></el-input>
</div>
</div>
<!-- 表格 -->
<div class="table">
<el-table
:data="tables"
style="width: 100%"
max-height=500>
<!-- 地址 -->
<el-table-column label="時(shí)間">
<template slot-scope="scope">
<span class="col-cont" v-html="showDate(scope.row.date)" ></span>
</template>
</el-table-column>
<!-- 用戶(hù)名 -->
<el-table-column label="用戶(hù)名">
<template slot-scope="scope">
<span class="col-cont" v-html="showDate(scope.row.name)" ></span>
</template>
</el-table-column>
<!-- 地址 -->
<el-table-column label="地址">
<template slot-scope="scope">
<span class="col-cont" v-html="showDate(scope.row.address)" ></span>
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<script>
export default {
data() {
return {
search: '',
tableData: [{
date: '2016-05-02',
name: '張三',
address: '上海市普陀區(qū)金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '李四',
address: '上海市普陀區(qū)金沙江路 1517 弄'
}, {
date: '2016-05-01',
name: '王五',
address: '上海市普陀區(qū)金沙江路 1519 弄'
}, {
date: '2016-05-03',
name: '趙六',
address: '上海市普陀區(qū)金沙江路 1516 弄'
}]
}
},
components: {},
computed: {
// 實(shí)時(shí)監(jiān)聽(tīng)表格
tables: function() {
const search = this.search
if (search) {
return this.tableData.filter(dataNews => {
return Object.keys(dataNews).some(key => {
return String(dataNews[key]).toLowerCase().indexOf(search) > -1
})
})
}
return this.tableData
}
},
mounted() {},
methods: {
// 篩選變色
showDate(val) {
val = val + '';
if (val.indexOf(this.search) !== -1 && this.search !== '') {
return val.replace(this.search, '<font color="#409EFF">' + this.search + '</font>')
} else {
return val
}
}
}
}
</script>
效果圖:

關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專(zhuān)題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請(qǐng)閱讀專(zhuān)題《vue實(shí)戰(zhàn)教程》
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue.js實(shí)現(xiàn)多條件篩選、搜索、排序及分頁(yè)的表格功能
- vue分類(lèi)篩選filter方法簡(jiǎn)單實(shí)例
- vuejs實(shí)現(xiàn)本地?cái)?shù)據(jù)的篩選分頁(yè)功能思路詳解
- 基于Vue實(shí)現(xiàn)的多條件篩選功能的詳解(類(lèi)似京東和淘寶功能)
- VUE實(shí)現(xiàn)移動(dòng)端列表篩選功能
- vue商城中商品“篩選器”功能的實(shí)現(xiàn)代碼
- vue實(shí)現(xiàn)前端列表多條件篩選
- vue+element table表格實(shí)現(xiàn)動(dòng)態(tài)列篩選的示例代碼
- vue3自定義動(dòng)態(tài)不同UI組件篩選框案例
相關(guān)文章
淺談Vue.nextTick 的實(shí)現(xiàn)方法
本篇文章主要介紹了Vue.nextTick 的實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
vue全局實(shí)現(xiàn)數(shù)字千位分隔符格式
這篇文章主要為大家詳細(xì)介紹了vue全局實(shí)現(xiàn)數(shù)字千位分隔符格式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10
Vue3響應(yīng)式方案及ref?reactive的區(qū)別詳解
眾所周知ref和reactive都是用來(lái)作響應(yīng)式數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于Vue3響應(yīng)式方案及ref?reactive區(qū)別的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
vue.js利用Object.defineProperty實(shí)現(xiàn)雙向綁定
這篇文章主要為大家詳細(xì)介紹了vue.js利用Object.defineProperty實(shí)現(xiàn)雙向綁定,幫大家解析神秘的Object.defineProperty方法2017-03-03
vue數(shù)字類(lèi)型過(guò)濾器的示例代碼
本篇文章主要介紹了vue數(shù)字類(lèi)型過(guò)濾器的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09

