前端analysis | 3w & 1h

《typescript》- 精读typescript

2020-11-03

模块

export default vs export

  • export default 只能出现一次,export not
  • export default ,xx 可以是{},function(){},and others
  • export ,xx可以是{}, const str = xx等形式

export

* export 字符串
1
2
# demo.js
export default 'hello world'
* export default {}
1
2
3
4
#demo.js
export default {
hello:'hello',
}
* export {}
1
2
3
4
5
6
const hello = 'hello'
export {
hello,
}
#or
export const hello = 'hello'

import

* import 字符串
1
2
# foo = 'hello world'
import foo from demo.js
* import from default
1
2
3
4
# foo =  {
hello:'hello',
}
import foo from demo.js
* import {}
1
2
# hello = 'hello'
import { hello } from demo.js
Tags: ts
使用支付宝打赏
使用微信打赏

若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏