1, 命名导出
es6:
命名导出:
1.1 声明时直接导出(在文件 module.js中)
export const PI = 3.14
export function greatFun(name) {
return `Hello ${name}`
}
1.2 先声明后导出
const PI = 3.14
function GereatFun(name){
reutrn `hello ${name}`
}
export {PI, GreatFun}
接下来导入
import {greatFun, PI} from "./module.js"
2,默认导出
默认导出(一个文件中只能有一个默认导出)
(在greate.js文件中编辑)
2.1 声明时直接导出
export default function great(name){
return `hello, ${name}`
}
2.2 先声明后导出
function great (name) {
return `hello, ${name}`
}
export default great
导入 默认导出
import great from "./greate.js"
3,在import中使用as
// 将module.js中的所有导出内容聚合到module对象中
import * as module from "./module.js"
// 假设great.js中great函数式命名导出
import { great as sayHello } from "./great.js"
565

被折叠的 条评论
为什么被折叠?



