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