export default VS exports VS modules.export

export deafult Vs module.export

在一個node執(zhí)行一個文件時,會給這個文件內(nèi)生成一個 exports和module對象
exports 是對module.export的引用, 簡單而言就是 exports === module.export

exports VS export default

  • export default命令,為模塊指定默認(rèn)輸出。
  • export與export default均可用于導(dǎo)出常量、函數(shù)、文件、模塊等
  • 在一個文件或模塊中,export、import可以有多個,export default僅有一個
  • 通過export方式導(dǎo)出,在導(dǎo)入時要加{ },export default則不需要
  • export能直接導(dǎo)出變量表達(dá)式,export default不行。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容