這個問題在這里已經有了答案: 帶有 src AND 內容的腳本標簽是什么意思? (4 個回答) 1 小時前關閉。
每當我連接一個 JS 模塊時,在 DevTools 的“源”中,該模塊都顯示為已連接。但是,我試圖用完它的功能根本不起作用。
可以做什么來運行模塊中的功能?
function consoleLog () {
console.log('The module is working')
}
export default consoleLog;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="module" src="./module.js">
import consoleLog from './module';
consoleLog();
</script>
</head>
<body>
</body>
</html>
uj5u.com熱心網友回復:
你的問題是src你的腳本標簽上有代碼和屬性,腳本標簽應該有一個或另一個。如果您將模塊匯入另一個模塊,您也不必為您的模塊創建腳本標記,如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="module">
import consoleLog from './module.js';
consoleLog();
</script>
</head>
<body>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/361095.html
標籤:javascript 进口 模块 出口
上一篇:開發一個JavaScript來查找給定字串“efg”第3次出現的位置I/P:abcefgacefgabcceftyefghjklopO/p:20
