vue+elementUI實現(xiàn)表格關(guān)鍵字篩選高亮
更新時間:2020年10月26日 13:27:43 作者:木子Leo
這篇文章主要為大家詳細介紹了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)文章
Vue3響應(yīng)式方案及ref?reactive的區(qū)別詳解
眾所周知ref和reactive都是用來作響應(yīng)式數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于Vue3響應(yīng)式方案及ref?reactive區(qū)別的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2022-12-12vue.js利用Object.defineProperty實現(xiàn)雙向綁定
這篇文章主要為大家詳細介紹了vue.js利用Object.defineProperty實現(xiàn)雙向綁定,幫大家解析神秘的Object.defineProperty方法2017-03-03