我想replaceAll在打字稿和角度 10 中使用。
但我收到此错误:属性 'replaceAll' 在类型 'string' 上不存在。
这是我的代码:
let date="1399/06/08"
console.log(date.replaceAll('/', '_'))
Run Code Online (Sandbox Code Playgroud)
输出:13990608
如何修复我的打字稿以显示此功能?
我正在开发一个使用本地服务器的项目。
在这个项目中,我使用模块,所以我的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而不需要服务器呢?