当前位置:网站首页>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>
边栏推荐
- 化学试剂磷脂-聚乙二醇-氨基,DSPE-PEG-amine,CAS:474922-26-4
- MySQL free installation download and configuration tutorial
- C语言对文件的操作(完整版)
- Cholesterol-PEG-DBCO 胆固醇-聚乙二醇-二苯基环辛炔化学试剂
- The solution to the IDEA console not being able to enter information
- 力扣.三数之和/四数之和
- UE5 最新动态虚幻引擎全新版本引爆互联网
- 一种用QT实现即时通信软件表情发送与接收的思路
- 滴滴被罚超80亿!收集并泄露1.07亿条乘客人脸识别信息
- Redis-Hash
猜你喜欢

Learning and understanding of ROS service programming

学习JDBC之获取数据库连接的方式

四种常见的POST提交数据方式

Four common ways of POST to submit data

911崩了,自养号测评环境IP有哪些更好的选择

Cholesterol-PEG-Azide CLS-PEG-N3 Cholesterol-PEG-Azide MW:3400

Qt TreeView 问题记录

数据分析之SQL面试真题
![[Solved] ssh connection report: Bad owner or permissions on C:\\Users/XXX/.ssh/config](/img/53/8b5a12e7ed551dca52ada5dbb5d6b5.png)
[Solved] ssh connection report: Bad owner or permissions on C:\\Users/XXX/.ssh/config

IDEA overview and installation and debugging
随机推荐
DSPE-PEG-COOH CAS: 1403744-37-5 Phospholipid-polyethylene glycol-carboxy lipid PEG conjugate
C语言静态变量static
VS2019配置配置项目属性自定义输出目录与中间目录
WIN10,配置adb环境
pyspark.ml feature transformation module
UR3机器人运动学分析之逆运动学分析
map和set
钉钉企业内部-H5微应用开发
[Solved] ssh connection report: Bad owner or permissions on C:\\Users/XXX/.ssh/config
【Rhapsody学习笔记】1:Hello World
力扣.剑指offer05.替换空格
【Rhapsody学习笔记】3:Dishwasher
MySQL master-slave switching steps
5G的用途和工作原理
【Rhapsody学习笔记】2:Count Down
学习JDBC之获取数据库连接的方式
Rejection sampling note
Cholesterol-PEG-Azide CLS-PEG-N3 Cholesterol-PEG-Azide MW:3400
ROS subscription to multiple topics time synchronization problem
Pytorch study notes 13 - Basic_RNN
