CRA创建的项目。
utils/config.js
CONFIG={
test:'test
}
然后我在我的src/index.js(它是项目的根(导入
<Provider store={store}>
<Router>
<Switch>
<Route path='/' exact>
<MainContainer title={'Welcome to something'} />
</Route>
<Route path='/dummy' exact>
<DummyContainer />
</Route>
<Route path='/pop/:topicId' exact>
<Popup />
</Route>
<Route path='/app' exact>
<App />
</Route>
</Switch>
</Router>
</Provider>,
导入"utils/config";
我可以从我的组件访问CONFIG,该组件从src/index.js 调用
但是出现了无法访问CONFIG的错误。
有没有办法让CONFIG处于第一个状态?
谢谢。
请确保导出正确。它应该是默认导出或命名导出。尝试低于的更改
utils/config.js
export default {
test:'test'
}
js(它是项目的根(
import config from 'utils/config'
现在你可以随心所欲地使用你的config
对象