当前位置:网站首页>Node-v download and application, ES6 module import and export
Node-v download and application, ES6 module import and export
2022-07-26 08:53:00 【m0_ sixty-two million one hundred and sixty-eight thousand and 】
Module export :export { }
The way of named guidance
Be sure to export in curly brackets
let obj = {
name: " Zhang San "
}
// Named Export
// Be sure to export in curly brackets
export { obj }
Module import : import { } from " "
<script type="module">
// Named import
// Be sure to export in curly brackets
import { obj } from "./1.js"
console.log(obj);
</script>
If two Js The file has the same name , You can choose to use when importing as Change the variable name , Use the new variable name when calling
import { obj, fn as fn2, str1 } from "./1.js"
let obj = {
name: " Zhang San "
}
function fn(a, b) {
let s = a + b;
alert(s)
}
let str1 = " I am a word "
export { obj, fn, str1 }
// If two Js The file has the same name , You can choose to use when importing as Change the variable name
import { obj, fn as fn2, str1 } from "./1.js"
console.log(obj); // {name: ' Zhang San '}
console.log(str1); // I am a word
function fn() {
alert(1)
}
fn2(1, 2) // 3
When many variables are exported , have access to *as To receive
import *as all from "./1.js"
// When many variables are exported , have access to *as To receive
import *as all from "./1.js"
console.log(all);
//Module {Symbol(Symbol.toStringTag): 'Module'}
fn: (…)
obj: (…)
str1: (…)
console.log(all.obj); // {name: ' Zhang San '}
all.fn(" Sun Li ", " Not Sun Li ")
// * It can also be exported separately , The name when exporting should be consistent with that when importing
// import { str1 } from "./1.js"
// console.log(str1); // I am a word
It is also used when exporting as Change the variable name
Separate export :
Separate export
export let obj = {
name: " Zhang San "
}
export function fn(a, b) {
let s = a + b;
alert(s)
}
export let str1 = " I am a word "
// Separate import
import { str1, fn, obj } from "./1.js"
console.log(str1); // {name: " Zhang San "}
console.log(obj); // I am a word
fn(" Sun Li ", " Not Sun Li ") // Sun Li Not Sun Li
Anonymous export : Export an object anonymously
export default { }
// Export an object anonymously
export default {
obj: {
name: " Zhang San "
},
str: " I am a word ",
strFn: function (a, b) {
alert(a + b)
}
}
Anonymous export You don't need curly braces , The name can be named arbitrarily
<script type="module">
// Anonymous export You don't need curly braces , The name can be named arbitrarily
import abc from "./2.js"
console.log(abc.obj); // {name: ' Zhang San '}
console.log(abc.str); // I am a word
abc.strFn(" Hello ", " China ") // Hello China
</script>
Write separately
// Write separately js part
let obj = {
name: " Zhang San "
}
let str = " I am a word ";
let strFn = function (a, b) {
alert(a + b)
}
export default {
obj: obj,
str: str,
strFn: strFn
}
// html part
<script type="module">
// Anonymous export You don't need curly braces , The name can be named arbitrarily
import abc from "./2.js"
console.log(abc.obj); // {name: ' Zhang San '}
console.log(abc.str); // I am a word
abc.strFn(" Hello ", " China ") // Hello China
</script>
// Write separately js part
let obj = {
name: " Zhang San "
}
let str = " I am a word ";
let strFn = function (a, b) {
alert(a + b)
}
// stay es6 in key and value It's the same situation , You can omit to write value
export default {
obj,
str,
strFn
}
// html part
<script type="module">
// Anonymous export You don't need curly braces , The name can be named arbitrarily
import abc from "./2.js"
console.log(abc.obj); // {name: ' Zhang San '}
console.log(abc.str); // I am a word
abc.strFn(" Hello ", " China ") // Hello China
</script>
node-v
Initialize a npm project :
npm init
Quickly initialize a npm project :
All content is default , The order is as follows :
npm init -y
Download the latest jquery Packet dependency , You can also use bootstrap,vue
npm install jquery
Use jquery
边栏推荐
- 数据库操作 题目一
- Spark persistence strategy_ Cache optimization
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- Oracle 19C OCP certification examination software list
- Oracle 19C OCP 1z0-082 certification examination question bank (51-60)
- 基于C语言实现的人机交互软件
- [recommended collection] MySQL 30000 word essence summary + 100 interview questions (I)
- 2022年收益率最高的理财产品是哪个?
- [freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls
- [search topics] flood coverage of search questions after reading the inevitable meeting
猜你喜欢
node-v下载与应用、ES6模块导入与导出
Neo eco technology monthly | help developers play smart contracts
Web3 Games: current situation and future
Review notes of Microcomputer Principles -- zoufengxing
at、crontab
Learning notes of automatic control principle --- linear discrete system
One click deployment of lamp and LNMP scripts is worth having
Pxe原理和概念
利用模m的原根存在性判断以及求解
Day06 operation -- addition, deletion, modification and query
随机推荐
合工大苍穹战队视觉组培训Day5——机器学习,图像识别项目
Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
Logic of data warehouse zipper table
tcp 解决short write问题
Sub Chocolate & paint area
C#入门系列(三十一) -- 运算符重载
One click deployment of lamp and LNMP scripts is worth having
C Entry series (31) -- operator overloading
Kotlin属性与字段
My meeting of OA project (meeting seating & submission for approval)
Recurrence of SQL injection vulnerability in the foreground of a 60 terminal security management system
Oracle 19C OCP certification examination software list
Sklearn machine learning foundation (linear regression, under fitting, over fitting, ridge regression, model loading and saving)
Kept dual machine hot standby
[untitled]
The largest number of statistical absolute values --- assembly language
Cadence (x) wiring skills and precautions
at、crontab
Web概述和B/S架构
The effective condition of MySQL joint index and the invalid condition of index