当前位置:网站首页>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>
边栏推荐
- Getting Started with MySQL: The Case Statement Works Well
- C语言结构体(必须掌握版)
- Webrtc从理论到实践三:角色
- 十分钟教你玩转分支语句!!!!!小白速进,新手福利!!
- MySQL free installation download and configuration tutorial
- [Solved] ssh connection report: Bad owner or permissions on C:\\Users/XXX/.ssh/config
- CSDN上markdown编写的一些便捷操作
- CAS: 1403744-37-5 DSPE-PEG-FA Phospholipid-Polyethylene Glycol-Folic Acid for Scientific Research
- 小型网站组建(ENSP)
- C语言数组的深度分析
猜你喜欢

Session和Cookie,Token

DingTalk Enterprise Internal-H5 Micro Application Development

Tensorflow steps on the pit while using it

map和set

DSPE-PEG-Biotin, CAS: 385437-57-0, phospholipid-polyethylene glycol-biotin prolongs circulating half-life

UE5 最新动态虚幻引擎全新版本引爆互联网

Cholesterol-PEG-DBCO 胆固醇-聚乙二醇-二苯基环辛炔化学试剂

概率论相关笔记

超详细!!!让你通透数组!!!初学复习不迷路!!

Detailed explanation of mysql transaction principle
随机推荐
Pytorch Daily Practice - Predicting Surviving Passengers on the Titanic
Unity Text一个简单的输入特效
ImportError: cannot import name 'Xxxx' from partially initialized module 'xx.xx.xx'
Fluorescein-PEG-DSPE Phospholipid-Polyethylene Glycol-Fluorescein Fluorescent Phospholipid PEG Derivatives
CAS:474922-22-0 Maleimide-PEG-DSPE Phospholipid-Polyethylene Glycol-Maleimide Brief Description
哈希表基础
力扣.两数之和/四数相加||
mPEG-DMPE Methoxy-polyethylene glycol-bismyristyl phosphatidylethanolamine for stealth liposome formation
Software Testing Interview Questions 2021
Qt TreeView 问题记录
Getting Started with MySQL: The Case Statement Works Well
Rejection sampling note
vs2022 xlua 集成第三方库编译报错Generator Visual Studio 15 2017 could not find any instance of Visual Studio.
CLS-PEG-FITC Fluorescein-PEG-CLS 胆固醇-聚乙二醇-荧光素简介
When solving background-size:cover, the picture is covered but not displayed completely?
IDEA overview and installation and debugging
在 AWS 上从零开始设置 Incredibuild 构建系统
ROS service transfer pictures
crontab timing operation
Virtual machine view port number process
