目前我有一个看起来像这样的导入
从“../../../components/Button/Button”导入按钮
但我想让它成为相对的,这样我就不需要一次又一次地输入 ../../../
。
我想用这个方法导入:
从 "components/Button/Button"导入 Button
或 src/components/Button/Button
但也请确保它适用于生产和开发。
最佳答案
如果您将 vscode 与使用 create-react-app 创建的项目一起使用,您可以尝试在根目录中添加一个 jsconfig.json 文件。
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
关于javascript - React.js 中的相对导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65713724/