当前位置:网站首页>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) // 3When 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

边栏推荐
- Cve-2021-3156 duplicate of sudo heap overflow privilege raising vulnerability
- Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
- P3743 kotori的设备
- [untitled]
- TypeScript版加密工具PasswordEncoder
- OA项目之我的会议(查询)
- Sub Chocolate & paint area
- TypeScript版Snowflake主键生成器
- Oracle 19C OCP 1z0-082 certification examination question bank (13-18)
- 《Datawhale熊猫书》出版了!
猜你喜欢

Uni app simple mall production
![[encryption weekly] has the encryption market recovered? The cold winter still hasn't thawed out. Take stock of the major events that occurred in the encryption market last week](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[encryption weekly] has the encryption market recovered? The cold winter still hasn't thawed out. Take stock of the major events that occurred in the encryption market last week
![[database] gbase 8A MPP cluster v95 installation and uninstall](/img/56/c0dae30ba608842c1b92e914ef42fe.png)
[database] gbase 8A MPP cluster v95 installation and uninstall

Super potential public chain dfinity -- the best time for DFI developers to enter

pl/sql之动态sql与异常

03 exception handling, state keeping, request hook -- 04 large project structure and blueprint

Solve the problem of C # calling form controls across threads

OA项目之我的会议(会议排座&送审)

MySQL 8.0 OCP (1z0-908) has a Chinese exam

My meeting of OA project (meeting seating & submission for approval)
随机推荐
Oracle 19C OCP 1z0-082 certification examination question bank (42-50)
Mysql database connection / query index and other common syntax
2000年的教训。web3是否=第三次工业革命?
Cadence (x) wiring skills and precautions
MySQL 8.0 OCP 1z0-908 certification examination question bank 1
Vision Group Training Day5 - machine learning, image recognition project
In the first year of L2, the upgrade of arbitrum nitro brought a more compatible and efficient development experience
Using the primitive root of module m to judge and solve
TypeScript版加密工具PasswordEncoder
Sub Chocolate & paint area
Which of count (*), count (primary key ID), count (field) and count (1) in MySQL is more efficient? "Suggested collection"
Human computer interaction software based on C language
What are the contents of Oracle OCP and MySQL OCP certification exams?
正则表达式:判断是否符合USD格式
day06 作业--技能题6
idea快捷键 alt实现整列操作
Which financial product has the highest yield in 2022?
Pxe原理和概念
[untitled]
pl/sql之动态sql与异常