当前位置:网站首页>JS import and export
JS import and export
2022-06-30 04:10:00 【Runqing】
export
Expression Export
// Export variables / Constant
export const name = 'hello'
export let addr = 'BeiJing City'
export var list = [1, 2 , 3]
// The export function
export function say (content){
console.log(content);
}
export function run (){
console.log('run')
}
// Export object
export ({
code: 0,
message: 'success'
})
// Export class
export class Test {
constructor(){
this.id = 2
}
}
Object based export
// Export variables / Constant
const name = 'hello'
let addr = 'BeiJing City'
var list = [1, 2 , 3]
export {
name,
addr,
list
}
// The export function
const say = (content) => {
console.log(content);
}
let run = () => {
console.log('run');
}
export {
say,
run
}
// Export object
let data = {
code: 0,
message: 'success'
}
export {
data
}
// Export class
class Test {
constructor(){
this.id = 2
}
}
export {
Test
}
The default is derived
A file can only have one default export module
See import for example
Import
Import of the default export module 、 Modify the export / Import module name
const name = 'hello'
let addr = 'BeiJing City'
let phone = 1234567
var list = [1, 2 , 3]
export {
name as cname,
addr as caddr,
phone
}
export default list
import list, {
cname, caddr, phone as cphone } from A
The overall import
const name = 'hello'
let addr = 'BeiJing City'
var list = [1, 2 , 3]
export {
name as cname,
addr as caddr
}
export default list
import list, * as mod from A
console.log(list);
console.log(mod.cname);
console.log(mod.caddr);
perhaps
import * as mod from A
// The default exported variables are exported in batches , You can use the attribute named default From the variables of
console.log(mod.default);
console.log(mod.cname);
console.log(mod.caddr);
边栏推荐
- Hebb and delta learning rules
- [Thesis reading | deep reading] role2vec:role based graph embeddings
- Unity échappe à l'entrée de caractères lors de l'entrée de chaînes dans l'éditeur
- Sql语句遇到的错误,求解
- After the win10 system uses the browser to download, the content is moved or deleted without reason
- Interface testing -- how to analyze an interface?
- 巧用 Bitmap 实现亿级海量数据统计
- Everyone, Flink 1.13.6, mysql-cdc2.2.0, the datetime (6) class extracted
- 毕业设计EMS办公管理系统(B/S结构)+J2EE+SQLserver8.0
- Day 12 advanced programming techniques
猜你喜欢

el-upload上传文件(手动上传,自动上传,上传进度)

Smart use of bitmap to achieve 100 million level massive data statistics

Share an example of a simple MapReduce method using a virtual machine

第十二天 进阶编程技术

关于智能视觉组上的机械臂

两个月拿到N个offer,什么难搞的面试官在我这里都不算事

Day 10 data saving and loading

How to analyze and solve the problem of easycvr kernel port error through process startup?

I spent three years in a big factory outsourcing, which subverted my understanding!

Wang Shuang - assembly language learning summary
随机推荐
01 backpack, dynamic planning
ThingsBoard教程(二三):在规则链中计算二个设备的温度差
RPC correction based on arcpy API
dotnet-exec 0.5.0 released
Quick sort & merge sort
The school training needs to make a registration page. It needs to open the database and save the contents entered on the registration page into the database
尝试链接数据库时出现链接超时报错,如何解决?
el-upload上傳文件(手動上傳,自動上傳,上傳進度)
About manipulator on Intelligent Vision Group
Postman learning sharing
Daily summary of code knowledge
dbt产品初体验
Solutions for project paths
Introduction to cloud native + container concept
Thingsboard tutorial (II and III): calculating the temperature difference between two devices in a regular chain
Maya Calendar(POJ1008)
lego_loam 代码阅读与总结
base64.c
dotnet-exec 0.5.0 released
【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码