当前位置:网站首页>node-v下载与应用、ES6模块导入与导出
node-v下载与应用、ES6模块导入与导出
2022-07-26 08:40:00 【m0_62168050】
模块导出:export { }
具名导处的方式
保证以花括号的形式导出
let obj = {
name: "张三"
}
// 具名导出的方式
// 保证以花括号的形式导出
export { obj }
模块导入: import { } from " "
<script type="module">
// 具名导入
// 保证以花括号的形式导出
import { obj } from "./1.js"
console.log(obj);
</script>
如果两个Js文件有相同的名字,可以选择导入的时候使用as修改变量名,调用的时候用新的变量名
import { obj, fn as fn2, str1 } from "./1.js"
let obj = {
name: "张三"
}
function fn(a, b) {
let s = a + b;
alert(s)
}
let str1 = "我是一句话"
export { obj, fn, str1 }
// 如果两个Js文件有相同的名字,可以选择导入的时候使用as修改变量名
import { obj, fn as fn2, str1 } from "./1.js"
console.log(obj); // {name: '张三'}
console.log(str1); // 我是一句话
function fn() {
alert(1)
}
fn2(1, 2) // 3
当导出了很多的变量,可以使用*as来接收
import *as all from "./1.js"
// 当导出了很多的变量,可以使用*as来接收
import *as all from "./1.js"
console.log(all);
//Module {Symbol(Symbol.toStringTag): 'Module'}
fn: (…)
obj: (…)
str1: (…)
console.log(all.obj); // {name: '张三'}
all.fn("孙莉", "不是孙俪")
// *也可以单独导出,导出的时候的名字需要和导入的时候的名字保持一致
// import { str1 } from "./1.js"
// console.log(str1); //我是一句话
在导出的时候也使用as修改变量名
分开导出:
分开导出
export let obj = {
name: "张三"
}
export function fn(a, b) {
let s = a + b;
alert(s)
}
export let str1 = "我是一句话"
// 分开导入
import { str1, fn, obj } from "./1.js"
console.log(str1); // {name: "张三"}
console.log(obj); // 我是一句话
fn("孙莉", "不是孙俪") //孙莉 不是孙俪
匿名导出:匿名导出一个对象
export default { }
// 匿名导出一个对象
export default {
obj: {
name: "张三"
},
str: "我是一句话",
strFn: function (a, b) {
alert(a + b)
}
}
匿名导出 不需要花括号,名字可任意命名
<script type="module">
// 匿名导出 不需要花括号,名字可任意命名
import abc from "./2.js"
console.log(abc.obj); // {name: '张三'}
console.log(abc.str); // 我是一句话
abc.strFn("你好", "中国") //你好中国
</script>
分开写的方式
// 分开写的方式 js部分
let obj = {
name: "张三"
}
let str = "我是一句话";
let strFn = function (a, b) {
alert(a + b)
}
export default {
obj: obj,
str: str,
strFn: strFn
}
// html部分
<script type="module">
// 匿名导出 不需要花括号,名字可任意命名
import abc from "./2.js"
console.log(abc.obj); // {name: '张三'}
console.log(abc.str); // 我是一句话
abc.strFn("你好", "中国") //你好中国
</script>
// 分开写的方式 js部分
let obj = {
name: "张三"
}
let str = "我是一句话";
let strFn = function (a, b) {
alert(a + b)
}
// 在es6中 key 和value 是一样的情况,可以省略写value
export default {
obj,
str,
strFn
}
// html部分
<script type="module">
// 匿名导出 不需要花括号,名字可任意命名
import abc from "./2.js"
console.log(abc.obj); // {name: '张三'}
console.log(abc.str); // 我是一句话
abc.strFn("你好", "中国") //你好中国
</script>
node-v
初始化一个npm项目:
npm init
快速初始化一个npm项目:
所有的内容都是默认的,命令如下:
npm init -y
下载一个最新jquery包依赖 ,也可以使用bootstrap,vue
npm install jquery
使用jquery
边栏推荐
- pl/sql之集合-2
- Xshell batch send command to multiple sessions
- IC's first global hacking bonus is up to US $6million, helping developers venture into web 3!
- 内存管理-动态分区分配方式模拟
- SSH,NFS,FTP
- 23.2 customizing the banner control display hidden banner modify banner
- Kotlin operator
- 23.10 Admin features
- P1825 [USACO11OPEN]Corn Maze S
- Oracle 19C OCP 1z0-082 certification examination question bank (24-29)
猜你喜欢
OA项目之我的会议(查询)
Kotlin属性与字段
In the first year of L2, the upgrade of arbitrum nitro brought a more compatible and efficient development experience
MySQL 8.0 OCP (1z0-908) has a Chinese exam
2000年的教训。web3是否=第三次工业革命?
SSH,NFS,FTP
Nodejs2day (modularization of nodejs, NPM download package, module loading mechanism)
Huffman transformation software based on C language
Mycat2 sub database and sub table
keepalived双机热备
随机推荐
6、 Pinda general permission system__ pd-tools-log
Problems caused by slivereappbar
Kotlin function
In the first year of L2, the upgrade of arbitrum nitro brought a more compatible and efficient development experience
正则表达式:判断是否符合USD格式
Oracle 19C OCP 1z0-082 certification examination question bank (13-18)
Cadence (x) wiring skills and precautions
P3743 kotori的设备
基于C语言实现的人机交互软件
[suggestions collection] summary of MySQL 30000 word essence - locking mechanism and performance tuning (IV) [suggestions collection]
[C language] programmer's basic skill method - "creation and destruction of function stack frames"
【搜索专题】看完必会的搜索问题之洪水覆盖
Dear teachers, how can sqlserver get DDL in flinkcdc?
Neo eco technology monthly | help developers play smart contracts
Xshell batch send command to multiple sessions
Transfer guide printing system based on C language design
Oracle 19C OCP 1z0-083 question bank (1-6)
Analysis on the query method and efficiency of Oracle about date type
基于C#实现的文件管理文件系统
Sub Chocolate & paint area