this.arrbooks.map((item, index) => { if (this.content) { let replaceReg = new RegExp(this.content, 'g'); let replaceString = '<span style="color:red;">' + this.content + '</span>'; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call (this.arrbooks[index] as any).cuts = (item as any).cuts.replace( replaceReg, replaceString ); } });
let replaceReg = new RegExp(this.content, 'g');// 全局匹配关键词let replaceString ='<span style="color:red;">' + this.content + '</span>';// 准备替换的内容(this.arrbooks[index] as any).cuts = (item as any).cuts.replace(replaceReg,replaceString);// 因为对象引用类型,属性改变自身也会改变,吧要替换的属性用正则替换