How to export how many classes with es6 export syntax?


我在用 es6 + react 写一个项目

▲ 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.

ExportThe statement must have a name, andexport {HeaderTop}In{HeaderTop}However, an anonymous object was created without specifying a name.

You can modify it toexport HeaderTopOrexport 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'
 import * from 'xxx'

Webpack2 will optimize this situation, compared toexport default {A, B}Be brief and efficient

Please refer directly to the detailed export and import syntax.Export statement-MDN