小编Mad*_*aby的帖子

“字符串”类型上不存在属性“replaceAll”

我想replaceAll在打字稿和角度 10 中使用。

但我收到此错误:属性 'replaceAll' 在类型 'string' 上不存在

这是我的代码:

let date="1399/06/08"
console.log(date.replaceAll('/', '_'))
Run Code Online (Sandbox Code Playgroud)

输出:13990608

如何修复我的打字稿以显示此功能?

typescript angular angular10

46
推荐指数
7
解决办法
3万
查看次数

如何在浏览器本地使用 javascript type="module"

我正在开发一个使用本地服务器的项目。

在这个项目中,我使用模块,所以我的index.html包含:

    <script src="js/index.js" type="module"></script>
Run Code Online (Sandbox Code Playgroud)

我的index.js包含:

    import {} from "/js/randomModule.js";
    import {} from "/js/randomModule.js";
    ...
Run Code Online (Sandbox Code Playgroud)

一切都运行得很完美,但是当我想在没有服务器的情况下直接在浏览器上使用该项目时,这就是问题:

Access to the script at 'file:///C:/Users/myFolder/js/index.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
index.html:54 

GET file:///C:/Users/myFolder/js/index.js net::ERR_FAILED
Run Code Online (Sandbox Code Playgroud)

那么,有没有一种方法可以type="module"在浏览器中直接使用javascript而不需要服务器呢?

javascript browser module server

5
推荐指数
2
解决办法
7741
查看次数

标签 统计

angular ×1

angular10 ×1

browser ×1

javascript ×1

module ×1

server ×1

typescript ×1