React 中导出模块的语法差异
Syntax difference in React for export module
以下 2 种语法之间有什么区别,这重要吗?
const Home = (props)=>{
return (
<div>Balbal {props.test}</div>
)
}
**module.exports= Home;**
const Home = (props)=>{
return (
<div>Balbal {props.test}</div>
)
}
**export default Home**
第一个是 'old' 导出语法,由 RequireJS to share objects and functions. The second is the more recent ES6 modules 语法使用,内置于 JavaScript。
在功能上,它们是相同的,但在支持的情况下,第二个现在可能被认为更惯用。
第一个名为导出。您可以导出多个 类 或变量,而 export default
用于导出单个 Class/variable。看这里了解更多https://developer.mozilla.org/en/docs/web/javascript/reference/statements/export
以下 2 种语法之间有什么区别,这重要吗?
const Home = (props)=>{
return (
<div>Balbal {props.test}</div>
)
}
**module.exports= Home;**
const Home = (props)=>{
return (
<div>Balbal {props.test}</div>
)
}
**export default Home**
第一个是 'old' 导出语法,由 RequireJS to share objects and functions. The second is the more recent ES6 modules 语法使用,内置于 JavaScript。
在功能上,它们是相同的,但在支持的情况下,第二个现在可能被认为更惯用。
第一个名为导出。您可以导出多个 类 或变量,而 export default
用于导出单个 Class/variable。看这里了解更多https://developer.mozilla.org/en/docs/web/javascript/reference/statements/export