Skip to content
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

Export default到底是什么含义? #14

Open
YutHelloWorld opened this issue Sep 26, 2017 · 0 comments
Open

Export default到底是什么含义? #14

YutHelloWorld opened this issue Sep 26, 2017 · 0 comments
Labels

Comments

@YutHelloWorld
Copy link
Owner

YutHelloWorld commented Sep 26, 2017

问题

// d.js
export default function() {}

为何使用require引用时需要取到解构default?而使用import d from './d'是正确的?

const  d = require('./d').default
// import d from './d'

来看下关键字default到底是什么

default关键字

// d.js
export default function() {}

// 等效于:
function a() {};
export {a as default};

Import

import a from './d';

// 等效于,或者说就是下面这种写法的简写,是同一个意思
import {default as a} from './d';

参考: http://imweb.io/topic/582293894067ce9726778be9

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