当前位置:网站首页>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脚本的程序

边栏推荐
- VB.net 调用FFmpeg简单处理视频(类库——6)
- 2022 R2 mobile pressure vessel filling retraining question bank and answers
- Wechat applet +php realizes authorized login
- Excel comparator
- Canoe panel learning video
- Gridview出现滚动条,组件冲突,如何解决
- JS flattened array of number shape structure
- (4) Canal multi instance use
- win10清除快速访问-不留下痕迹
- JS string splicing
猜你喜欢

报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。

input显示当前选择的图片
![[excel] PivotChart](/img/45/be87e4428a1d8ef66ef34a63d12fd4.png)
[excel] PivotChart

The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat

BUU-Reverse-easyre

Detectron:训练自己的数据集——将自己的数据格式转换成COCO格式

Accidentally deleted the data file of Clickhouse, can it be restored?
![[QT] create mycombobox click event](/img/5a/ed17567a71f6737891fc7a8273df0a.png)
[QT] create mycombobox click event

VB. Net simple processing pictures, black and white (class library - 7)

Ping port artifact psping
随机推荐
Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
【微服务】Nacos集群搭建以及加载文件配置
Letter meaning and parameter abbreviation of optical module Daquan
Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
一键过滤选择百度网盘文件
ansys命令
Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
注释与注解
如何判断数组中是否含有某个元素
input显示当前选择的图片
光模块字母含义及参数简称大全
Arc135 C (the proof is not very clear)
每周小结(*63):关于正能量
VB. Net calls ffmpeg to simply process video (class Library-6)
724. Find the central subscript of the array
Steady! Huawei micro certification Huawei cloud computing service practice is stable!
LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
Signification des lettres du module optique et abréviation des paramètres Daquan
谷歌 Chrome 浏览器将支持选取文字翻译功能
Google Chrome browser will support the function of selecting text translation