当前位置:网站首页>ES6-模块
ES6-模块
2022-07-31 05:18:00 【春意迟迟、】
ES6 引入了模块化,其设计思想是在编译时就能确定模块的依赖关系,以及输入和输出的变量。
导出(export)、导入(import)
<script type="module"> //导出的名字一定要相同 //默认导出不写{} import name from "./test.js" console.log(name) //rose </script>
有时候全局导出会污染我们现在代码的环境,还会加大不必要的开销,这时候可以使用按需导入
<script type="module"> //按需导出要写{} import {age,arr} from "./test.js" console.log(age,arr) </script>
<script type="module"> //按需导出和默认导出一起写 import name,{age,arr} from "./test.js" console.log(age,arr) </script>
注意:默认导出不写{},否则会报错
按需导出要写{},不然会报错
默认导出与按需导出都需要的时候,默认导出一定要写在前面,不然会报错
举两个例子:
<script type="module"> import { tool } from "./src/model1.js" import x from "./src/model1.js" x.tool import Hq from './src/model1.js' console.log(Hq.Photo) import { Photo as a } from './src/model1.js' let a = Photo console.log(Photo.name) </script>
<script type="module"> import x, { num, tool } from "./src/model1.js" console.log(num) console.log(tool) console.log(obj) var re = tool() console.log(re) console.log(x.arr) </script>
边栏推荐
- 5G的用途和工作原理
- UR3机器人雅克比矩阵
- 常见网络攻击与防御方法
- Wlan实验(ENSP)
- Picture-in-Picture API in the browser
- Remote file xxx is mapped to the local path xxx and can‘t be found. You can continue debugging....
- vs2022 xlua 集成第三方库编译报错Generator Visual Studio 15 2017 could not find any instance of Visual Studio.
- Cholesterol-PEG-Amine CLS-PEG-NH2 Cholesterol-Polyethylene Glycol-Amino Research Use
- Pytorch learning notes 09 - multiple classification problem
- The solution to the IDEA console not being able to enter information
猜你喜欢
CAS: 1403744-37-5 DSPE-PEG-FA Phospholipid-Polyethylene Glycol-Folic Acid for Scientific Research
DSPE-PEG-Thiol DSPE-PEG-SH 磷脂-聚乙二醇-巯基脂质体制备用
Pytorch study notes 13 - Basic_RNN
概率论相关笔记
911崩了,自养号测评环境IP有哪些更好的选择
DSPE-PEG-Thiol DSPE-PEG-SH phospholipid-polyethylene glycol-thiol liposome for later use
Learning and understanding of ROS service programming
Log jar package conflict, and its solution
The content of the wangeditor editor is transferred to the background server for storage
Software Testing Interview Questions 2021
随机推荐
学习JDBC之获取数据库连接的方式
pyspark.ml feature transformation module
【Rhapsody学习笔记】3:Dishwasher
ImportError: cannot import name ‘Xxxx‘ from partially initialized module ‘xx.xx.xx‘
Phospholipids-Polyethylene Glycol-Active Esters for Scientific Research DSPE-PEG-NHS CAS: 1445723-73-8
UR3机器人雅克比矩阵
Websocket协议解析与QT代码示例
911崩了,自养号测评环境IP有哪些更好的选择
力扣.剑指offer05.替换空格
超详细!!!让你通透数组!!!初学复习不迷路!!
Pytorch study notes 7 - processing input of multi-dimensional features
力扣.两数之和/四数相加||
Session和Cookie,Token
滴滴被罚超80亿!收集并泄露1.07亿条乘客人脸识别信息
可下载视频可下载图片的函数
DSPE-PEG-Biotin, CAS: 385437-57-0, phospholipid-polyethylene glycol-biotin prolongs circulating half-life
Unity软件中UGUI和NGUI的多语言开发
Shell/Vim related list
Unity转微信小游戏与JS交互
CAS:474922-22-0 Maleimide-PEG-DSPE Phospholipid-Polyethylene Glycol-Maleimide Brief Description