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

边栏推荐
- Typescript encryption tool passwordencoder
- Uni app simple mall production
- 2022年收益率最高的理财产品是哪个?
- node的js文件引入
- Huffman transformation software based on C language
- Regular expression: judge whether it conforms to USD format
- Foundry tutorial: writing scalable smart contracts in various ways (Part 1)
- pl/sql之动态sql与异常
- What are the differences in the performance of different usages such as count (*), count (primary key ID), count (field) and count (1)? That's more efficient
- CIS 2020 - alternative skills against cloud WAF (pyn3rd)
猜你喜欢

Set of pl/sql

数据库操作 题目一

有限元学习知识点备案

Regular expression: judge whether it conforms to USD format

2000年的教训。web3是否=第三次工业革命?

Sklearn machine learning foundation (linear regression, under fitting, over fitting, ridge regression, model loading and saving)

SSH,NFS,FTP

Day06 homework -- skill question 1

What are the contents of Oracle OCP and MySQL OCP certification exams?

Huffman transformation software based on C language
随机推荐
Vision Group Training Day5 - machine learning, image recognition project
Xshell batch send command to multiple sessions
Spark scheduling analysis
Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
03 exception handling, state keeping, request hook -- 04 large project structure and blueprint
6、 Pinda general permission system__ pd-tools-log
JDBC数据库连接池(Druid技术)
[recommended collection] MySQL 30000 word essence summary - query and transaction (III)
Memory management - dynamic partition allocation simulation
Learn more about the difference between B-tree and b+tree
[recommended collection] MySQL 30000 word essence summary index (II) [easy to understand]
基于C语言设计的换乘指南打印系统
My meeting of OA project (query)
Set of pl/sql -2
Huffman transformation software based on C language
Uni app simple mall production
day06 作业--技能题1
Mysql database connection / query index and other common syntax
C Entry series (31) -- operator overloading
[untitled]