[英]Import/export module in JavaScript
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script src="./app.js"></script>
</body>
</html>
應用程序.js
import { hello } from './hello';
hello();
你好.js
export function hello() {
console.log('Hello!');
}
未捕獲的語法錯誤:無法在模塊 app.js:1 之外使用導入語句
我認為您需要在腳本標簽中添加類型:
<script type="module" src="./app.js"></script>
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.