export和export default的区别

export的使用

1.直接输出

export let words = 'hello world!!!' 

export function output() { 
  // ... 
}

2.先定义再输出

复制代码

let firstWords = 'hello'
let secondWords = 'world'
let thirdWords = '!!!'

function output() {
    // ...
}

export {firstWords, secondWords, thirdWords, output}

复制代码

export default的使用

1.export default 用于规定模块的默认对外接口
2.很显然默认对外接口只能有一个,所以 export default 在同一个模块中只能出现一次
3.export default只能直接输出,不能先定义再输出。

4.其在 import 方式上也和 export 存在一定区别

(1)export的输出与import输入

export function output() {
    // ...
}

import {output} from './example'

(2)export default的输出与import输入

export default function output() {
    // ...
}

import output from './example'

从以上两种 import 方式即可看出,export default 的 import 方式不需要使用大括号包裹。因为对于 export default 其输出的本来就只有一个接口,提供的是模块的默认接口,自然不需要使用大括号包裹。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值