简体   繁体   English

replaceAll function 被标记为...?

[英]replaceAll function is being marked as...?

The code you are seeing technically works.您看到的代码在技术上有效。 But VS Code, shows me an underline under the replaceAll function.但是 VS Code 在replaceAll function 下显示了一个下划线。 I would like to know why, and what I could do to avoid this happening again.我想知道为什么,以及我能做些什么来避免这种情况再次发生。

renderTemplateText(str) {
    var parser = new DOMParser();
    var doc = parser.parseFromString(str, "text/html");
    var xRepeat = doc.querySelectorAll('[x-repeat]');
    var divarray = doc.querySelectorAll('[is^="x-"]');
    var divarraylength = divarray.length;


    for (var i = 0; i < divarraylength; i++) {                                                           
            var dataAttribute = divarray[i].getAttribute('data-link');                                                  
            console.log(divarray[i]);                                                    
            if (dataAttribute !== null) {                                           
                dataAttribute = dataAttribute.replaceAll("props", this.propsname);
            }                                                              
            console.log(dataAttribute );
    }
}

This can be fixed by changing your jsconfig.json target to es2021, since String.replaceAll is a ES2021 feature.这可以通过将 jsconfig.json 目标更改为 es2021 来解决,因为 String.replaceAll 是 ES2021 功能。

Example:例子:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2021",
        "jsx": "preserve",
        "strictFunctionTypes": true
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ],
    "include": [
        "**/**/*"
    ]
}

You can honestly just ignore this.老实说,您可以忽略这一点。 It's just a VS Code thing.这只是一个 VS Code 的事情。 I am assuming it works?我假设它有效? I made the not given value props myself, and it worked fine.我自己制作了未给定的价值道具,效果很好。

If you really want to fix this though, you have to change your jsconfig.json target to "es2021".如果你真的想解决这个问题,你必须将你的 jsconfig.json 目标更改为“es2021”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM