vue+elementUI实现表格关键字筛选高亮
本文实例为大家分享了vue elementUI表格关键字筛选高亮的具体代码,供大家参考,具体内容如下
代码:
<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="请输入关键字"></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: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '李四', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王五', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '赵六', address: '上海市普陀区金沙江路 1516 弄' }] } }, components: {}, computed: { // 实时监听表格 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>
效果图:
相关推荐
fenghuoliuxing0 2020-08-01
yhuihon 2020-05-31
苗疆三刀的随手记 2020-05-27
玫瑰小妖 2020-05-10
心丨悦 2020-05-08
zhanghaibing00 2020-04-21
Lius 2020-02-14
vshacker 2020-01-28
James0 2019-12-15
rootdream 2019-11-17
zycglboy 2019-11-12
Urchindong 2011-08-01
Mexican 2014-03-19
genglang 2018-08-17
89589432 2019-09-22
技术相关 2019-04-23
Tomato 2018-10-17