(vue)Vue前台警告You may have an infinite update loop in watcher with expression

(vue)Vue前台警告You may have an infinite update loop in watcher with expression

原因:循环的数组设置了全局(和我的特殊数组有关)

修改前:

    //遍历标签
    changeCompare(val, keyword) { 
        this.textList.forEach((item1) => {
          this.color = item1.color; //区别
          this.contentTest = item1.content; //区别
          this.contentTest.forEach((item) => {
            keyword = item;
            val = val + "";
            if (val.indexOf(item) !== -1 && item !== "") {
              val = val.replace(
                new RegExp(item, "g"),
                `<font color='#000' style="
        background-color: ${this.color};
        border-radius: 5px;
        padding: 2px 4px; margin:2px;">${item}</font>`
              );
            }
          });
        });
        return val; 
    },

修改后:

    //遍历标签
    changeCompare(val, keyword) { 
        this.textList.forEach((item1) => { 
          var color = item1.color; //区别
          var contentTest = item1.content; //区别
          contentTest.forEach((item) => {
            keyword = item;
            val = val + "";
            if (val.indexOf(item) !== -1 && item !== "") {
              val = val.replace(
                new RegExp(item, "g"),
                `<font color='#000' style="
        background-color: ${color};
        border-radius: 5px;
        padding: 2px 4px; margin:2px;">${item}</font>`
              );
            }
          });
        });
        return val; 
    },

解决参考:
https://blog.csdn.net/qq_42569573/article/details/106691756

https://blog.csdn.net/weixin_46820017/article/details/122229053

https://www.jianshu.com/p/a51fb3694673?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值