vue+elementUI實現(xiàn)表格關(guān)鍵字篩選高亮
本文實例為大家分享了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="請輸入關(guān)鍵字"></el-input>
</div>
</div>
<!-- 表格 -->
<div class="table">
<el-table
:data="tables"
style="width: 100%"
max-height=500>
<!-- 地址 -->
<el-table-column label="時間">
<template slot-scope="scope">
<span class="col-cont" v-html="showDate(scope.row.date)" ></span>
</template>
</el-table-column>
<!-- 用戶名 -->
<el-table-column label="用戶名">
<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: {
// 實時監(jiān)聽表格
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組件的教程,請大家點擊專題vue.js組件學(xué)習(xí)教程進行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請閱讀專題《vue實戰(zhàn)教程》
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于vue-admin-element中的動態(tài)加載路由
這篇文章主要介紹了關(guān)于vue-admin-element的動態(tài)加載路由,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
解決npm安裝錯誤:No matching version found for&
這篇文章主要介紹了解決npm安裝錯誤:No matching version found for XXX@3.3.6問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07
Vue中對watch的理解(關(guān)鍵是immediate和deep屬性)
watch偵聽器,是Vue實例的一個屬性,是用來響應(yīng)數(shù)據(jù)的變化,需要在數(shù)據(jù)變化時執(zhí)行異步或開銷較大的操作時,這個方式是最有用的,這篇文章主要介紹了Vue中對watch的理解,需要的朋友可以參考下2022-11-11
vue2.0基于vue-cli+element-ui制作樹形treeTable
這篇文章主要介紹了vue2.0基于vue-cli+element-ui制作樹形treeTable,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04

