我正在使用 React 并且我在多个高阶组件中使用了多个组件,我的导入有时会像这样import MyComponent from '../../../../components/MyComponent'
我知道有一种更有效的方法可以通过更改 package.json 文件中的内容然后导入来导入它它有点像这样,import MyComponent from '@components/myComponent'
但我不记得我该怎么做,我该怎么做?
你可以通过使用jsconfig
或者tsconfig
如果你正在使用 TypeScript来做到这一点。
npm start
。jsconfig.json
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
如果您使用 Next.js,这可能会有所帮助https://nextjs.org/docs/advanced-features/module-path-aliases
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句