Add highlighting helper functions
// The source string, the fragment to highlight
export const heightLight = (str, key) = > {
const reg = new RegExp(key, 'ig')
return str.replace(reg, (val) = > {
return `<span style="color:red">${val}</span>`})}Copy the code
Adding computed Attributes
computed: {
cSuggestions () {
Replace each item in your suggestions
// Each item in your suggestions ====> heightLight(each item in your Suggestions, this.keyword)
return this.suggestions.map(item= > {
return heightLight(item, this.keyword)
})
}
},
Copy the code
Loop through the calculated properties with V-for
<! --2.Search SuggestionsCopy the code