Skip to content

export和export default区别 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Twlig opened this issue Mar 10, 2022 · 0 comments
Open

export和export default区别 #29

Twlig opened this issue Mar 10, 2022 · 0 comments
Labels

Comments

@Twlig
Copy link
Owner

Twlig commented Mar 10, 2022

导出差别

1、export

  • export 可以直接导出或者先定义后导出都可以。
    示例:
export let i = “hello”;
export function myFun(){};
  • 上面的直接导出,也可以使用下面先定义后导出。
let i = “hello";
function myFun(){};
export {i , myFun}

2、export default

  • export default是模块的默认对外接口,只有一个,所以只能出现一次。
  • export default只能直接输出,不能先定义后导出。
export default {
    props: {
        foo: 'foo'
    }
}

导入差别

1、export导出的对象,导入时写法:

import {i, myFun}

2、export default导出的对象,导入时写法:

import 变量名 from ‘模块’

很明显,模块只有一个默认的导出的接口,所以只有一个对象被导出,导出的对象可以自定义一个变量名。

原文链接:export和export default区别
@Twlig Twlig added the Node label Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant