Home > Web Front-end > JS Tutorial > Code for highlighting keywords in search results in vue2

Code for highlighting keywords in search results in vue2

不言
Release: 2018-08-20 14:28:00
Original
2731 people have browsed it

The content of this article is about the code for highlighting keywords in search results in vue2. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

// Filter color change

brightenKeyword(val, keyword) {
   val = val + '';
   if (val.indexOf(keyword) !== -1 && keyword !== '') {
        return val.replace(keyword, '<font color="#409EFF">' + keyword + '</font>')
   } else {
      return val
    }
}
Copy after login

// Usage method

<el-table-column label="维护内容">
   <template slot-scope="scope">
      <span v-html="brightenKeyword(scope.row.strContent, filters.strContent)" ></span>
   </template>
</el-table-column>
Copy after login

Open source project address: https://github.com/alex-0407/...

Related recommendations:

JS’s regular replace search keyword highlighting effect

Use JS to highlight the search keywords Implementation code_javascript skills

The above is the detailed content of Code for highlighting keywords in search results in vue2. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template