【发布时间】:2016-09-23 03:31:22
【问题描述】:
有什么区别
import Something from 'react';
和
import {Something} from 'react';
这些花括号是什么意思?
【问题讨论】:
标签: reactjs
有什么区别
import Something from 'react';
和
import {Something} from 'react';
这些花括号是什么意思?
【问题讨论】:
标签: reactjs
import Something from 'react';
导入模块导出的default 是什么。
在这种情况下,导出应该是这样的
export default const Something = function(){...}
import {Something} from 'react'; 导入一个命名的导出,比如
export const Something = function(){}
如果您的模块同时具有default 和命名导出,您可以将它们导入一个like。示例
//module A
export default const Something = function(){}
export const SomethingElse = function(){}
然后像这样导入它们
//module B
import Something, { SomethingElse } from 'moduleA';
之前的default不必导入为Something,你可以用任何你想要的名字导入。
import A from 'moduleA'
等于
import Something from 'moduleA'
【讨论】: