我有这样的项目结构:
- MyApp
`- firstFolder
`- firstFile.js
`- secondFolder
`- thirdFolder
`- thirdFile.js
如何导入firstFile.js
从thirdFile.js
?
喜欢的东西import myFunc from '../firstFolder/firstFile';
在thirdFile.js
,不能正常工作。
../将返回1个文件夹,这就是为什么我们返回两个文件夹的原因:
import myFunc from ../../firstFolder/firstFile.js;
否则这些将从根目录开始
import myFunc from /firstFolder/firstFile.js
import myFunc from ./firstFolder/firstFile.js
import myFunc from ~/firstFolder/firstFile.js
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句