首先贴代码
let list = data.items;
for(let i=0;i<list.length;i++){
let str;
let reg = new RegExp("(" + this.searchVal + ")", "g");
str = list[i].name.replace(reg,"<span style='color:#288FF6;'>$1</span>");
list[i].name = str;
}
this.villageList = list;
这样基本就可以了,但最后千万别忘记加 v-html,不然会直接编译成字符串
来源:https://www.cnblogs.com/luckyL/p/12563895.html