I'm working on implementing a search feature that will bold the matching parts. For example, if I have the name 'John' and search for 'Jo Joh' in the same string, I want it to bold the part of 'John' that has the most matches, so it should display as John.
Here's what I have so far, but I'm running into an issue with the error message "error during evaluation" in my Vue Tools debugger.
computed: {
bold: function () {
var compare = [];
var word = 'john';
var array = ['jo', 'joh'];
for (var i = 0; i < array.length; i++) {
if (word.contains(array[i])) {
compare[i] = array[i];
}
}
var maxWord = compare[0];
for (var i = 0; i < compare.length - 1; i++) {
if (maxWord.length < compare[i].length) {
maxWord = compare[i];
}
}
return word.toString().replace(maxWord, '<strong>' + maxWord + '</strong>');
}
}