// 1、默认导出变量
const test = 'hellow world'
export default test
import testStr from './test.js'
console.log(testStr) // hellow world
// 2、默认导出函数
const request = (params) => {
return {
name: 'zhangsan',
age: 10
}
}
export default request;
import requestFn from './test.js'
console.log(requestFn()) // {name: 'zhangsan', age: 10}
// 3、默认导出对象
const page = 10;
const currrent = 0;
export default {
page,
currrent
}
import pageObj from './test.js'
console.log(pageObj) // {page: 10, currrent: 0}
// 1、多个导出
export function test1() {
console.log('tst1')
}
export function test2() {
console.log('tst2')
}
import { test1, test2 } from './test.js'
// 2、多个导出合并写法
function test1() {
console.log('tst1')
}
function test2() {
console.log('tst1')
}
export {
test1,
test2
}
import { test1, test2 } from './test.js'
// 3、再导出
function test1() {
console.log('tst1')
}
function test2() {
console.log('tst1')
}
export {
test1,
test2
}
// 导入区块代码
export { test1, test2 } from './test.js'
// 上面代码等同于
import { test1, test2 } from './test.js'
export { test1, test2 }
// 4、导出所有
export function test1() {
console.log('test1')
}
export function test2() {
console.log('test2')
}
// 中间文件index.js
export * from './test.js'
export * from './test2.js'
import { test1, test2 } from './index.js'
console.log(test1()) // test1
export、import
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Export 模块是独立的文件,该文件内部的所有的变量外部都无法获取。如果希望获取某个变量,必须通过export输...
- COMMONJS规范 1.了解 node应用由模块组成,采用的commonjs模块规范。每一个文件就是一个模块,拥...
- ES6的模块通过export命令规定模块的对外接口,用import命令引入其他模块提供的功能。然而export命令...
- yscmh 关注 2018.08.22 18:47* 字数 599 阅读 33评论 1喜欢 1 1.export ...
- ES6模块主要有两个功能:export和importexport用于对外输出本模块(一个文件可以理解为一个模块)变...