網站首頁 編程語言 正文
node v13.2.0之后
只需要在新建node項目(使用一個package.json文件和一個對應node_models即可)package.json中添加屬性:"type": "module"
已驗證好用
嘗試案例
將index.html,export.js,import.js,package.json,node_modules放到一個目錄下
package.json中添加屬性:"type": "module"

用瀏覽器打開index.html即可練習es6模塊化

index.html文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<!-- 看這 -->
<script type="module" src="./import.js"></script>
</head>
<body></body>
</html>
export.js
export let name = 'jack';
export let age = 18;
import.js
// 名稱要跟導出的模塊名稱一一對應,同時from后為導入模塊的路徑
import {name,age} from './export.js'
console.log(`我叫${name},今年${age}歲`);

原文鏈接:https://blog.csdn.net/qiuyushuofeng/article/details/124790029
相關推薦
- 2022-07-17 Android?studio實現簡易的計算器功能_Android
- 2023-05-22 關于PyTorch中nn.Module類的簡介_python
- 2022-07-19 react Context的基本使用( react跨組件傳遞數據 )
- 2023-12-13 在Excel中找出某個重復項并用顏色標示出來
- 2022-06-15 golang?數組去重,利用map的實現_Golang
- 2022-05-21 Python遞歸時間復雜度_python
- 2022-05-25 @Service未注入、 @Autowired未自動注入
- 2022-05-11 linq中的連接操作符_實用技巧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支