当前位置:网站首页>ES6 模块化
ES6 模块化
2022-07-04 05:46:00 【玉安_ZhangDe】
ES6 模块化 简介
ES6 模块化规范是 浏览器端 与 服务器端 通用的模块化开发规范。它的出现极大的降低了前端开发者的模块化学习成本,开发者不需要再额外学习 AMD(AMD yes !!! XD)、CMD 或 CommonJS等模块化规范。
ES6 模块化规范中定义:
- 每个js文件都是一个独立的模块
- 导入其他模块成员使用 import 关键字
- 向外共享模块成员使用 export 关键字
在node.js中体验 ES6 模块化
- 确保安装了 v14.15.1 或更高版本的node.js
- 在 package.json 的根节点中添加 "type": "module" 节点
默认导出 和 默认导入
每个js脚本里面只能使用唯一一次 export default ,否则会报错
// 默认导出
// 每个js脚本里面只能使用唯一一次 export default ,否则会报错
let m1 = 10
let m2 = 20
let f1 = () =>{}
export default {
m1,
f1
}
// 默认导入
// 路径务必将文件后缀写上
import i1 from './01.默认导出.js'
console.log(i1)
按需导出 和 按需导入
// 按需导出
export let s1 = 'aaa'
export let s2 = 'ccc'
export const add = x => x+10
// 按需导入
// 传过来发现和当前 js脚本的变量名有冲突,我们可以用 as 更改 名字,只在当前js脚本内有效
import {s1 as ss,s2,add} from './03.按需导出.js'
let s1 = 10
console.log(ss)
console.log(s2)
console.log(s1)
console.log(add(s1))
直接导入
直接导入会执行被导入js脚本的程序
边栏推荐
- 1.1 history of Statistics
- 如何判断数组中是否含有某个元素
- LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
- One click filtering to select Baidu online disk files
- (4) Canal multi instance use
- LC weekly 300
- SQL performance optimization skills
- Uninstall Google drive hard drive - you must exit the program to uninstall
- Accidentally deleted the data file of Clickhouse, can it be restored?
- Canoe panel learning video
猜你喜欢
VB. Net GIF (making and disassembling - optimizing code, class library - 5)
(4) Canal multi instance use
Ping port artifact psping
Leakage detection relay jy82-2p
[QT] create mycombobox click event
BUU-Real-[PHP]XXE
光模塊字母含義及參數簡稱大全
win10清除快速访问-不留下痕迹
VB.net GIF(制作、拆解——优化代码,类库——5)
Simulink and Arduino serial port communication
随机推荐
检漏继电器JY82-2P
Ping port artifact psping
Redis realizes ranking function
How to configure static IP for Kali virtual machine
Google Chrome browser will support the function of selecting text translation
SQL performance optimization skills
"In simple language programming competition (basic)" part 1 Introduction to language Chapter 3 branch structure programming
VB.net 调用FFmpeg简单处理视频(类库——6)
fastjson
Halcon image calibration enables subsequent image processing to become the same as the template image
How to implement lazy loading in El select (with search function)
LC周赛300
Talk about the SQL server version of DTM sub transaction barrier function
Basic concept of bus
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
gslb(global server load balance)技术的一点理解
Descriptive analysis of data distribution characteristics (data exploration)
JS string splicing
Supplement the JS of a video website to decrypt the video
总线的基本概念