npm i vue-highlight-words
App.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<template> <div id="app"> // attrs on component are applied to the wrapper <Highlighter class="my-highlight" :style="{ color: 'blue' }" highlightClassName="highlight" :searchWords="keywords" :autoEscape="true" :textToHighlight="text"/> </div> </template> <script> import Highlighter from 'vue-highlight-words' export default { name: 'app', components: { Highlighter }, data() { return { text: 'The dog is chasing the cat. Or perhaps they\'re just playing?', words: 'and or the dog' } }, computed: { keywords() { return this.words.split(' ') } } } </script> |