▲ Background: Above: I am writing a project with es6 plus react.
▼ Question: As follows:
I use es6′ s export to export a class (a component of react).
As shown in the figure, the other exports were successful, onlyexport {HeaderTop}
This cannot be exported
So, if my file has multiple classes (that is, multiple components), how do I export it? Thank you, old hand.
May old hand have a happy life and thank you for your advice.
–
–
Export
The statement must have a name, andexport {HeaderTop}
In{HeaderTop}
However, an anonymous object was created without specifying a name.You can modify it to
export HeaderTop
Orexport default HeaderTop
. And the corresponding import place is respectivelyimport {HeaderTop} from 'xxx'
Andimport HeaderTop from 'xxx'
If there are multiple objects to export, it is recommended to write as follows:
export class A {...} export class B {...}
The imported place can be used as follows:
import {A, B} from 'xxx' //or: import * from 'xxx'
Webpack2 will optimize this situation, compared to
export default {A, B}
Be brief and efficientPlease refer directly to the detailed export and import syntax.Export statement-MDN