首页 > IT职业 > IT图书 > vue2实现搜索结果中的搜索关键字高亮
// 筛选变色
brightenKeyword(val, keyword) {
val = val + ''; if (val.indexOf(keyword) !== -1 && keyword !== '') { return val.replace(keyword, '<font color="#409EFF">' + keyword + '</font>')
} else { return val
}
}
// 使用方法
<el-table-column label="维护内容"> <template slot-scope="scope"> <span v-html="brightenKeyword(scope.row.strContent, filters.strContent)" ></span> </template></el-table-column>

vue2-admin-grace.gif
作者:全栈弄潮儿
链接:https://www.jianshu.com/p/7e8ec4394480
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/933/viewspace-2815577/ ,如需转载,请注明出处,否则将追究法律责任。