从容器中导入组件(从范围外)
Importing a component from containers (From outside of the scope)
我对反应很陌生,在解决这个基本问题时遇到了一些麻烦。
来自 HomeLander.js - 如何导入按钮和 P?正如预期的那样,它们不在同一范围内。有没有一个巧妙的方法来做到这一点?
我的目录结构是这样的:
- 组件/
- 按钮/
- index.js
- P/
- index.js
- 容器/
- 家园登陆/
- index.js
- Index.js(“主要”JS 文件)
你可以试试这个
import Button from '../../Components/Button'; (given Button component is default export)
import { Button } from '../../Components/Button'; (if Button component is not default export)
与'P'
相同
我对反应很陌生,在解决这个基本问题时遇到了一些麻烦。
来自 HomeLander.js - 如何导入按钮和 P?正如预期的那样,它们不在同一范围内。有没有一个巧妙的方法来做到这一点?
我的目录结构是这样的:
- 组件/
- 按钮/
- index.js
- P/
- index.js
- 按钮/
- 容器/
- 家园登陆/
- index.js
- 家园登陆/
- Index.js(“主要”JS 文件)
你可以试试这个
import Button from '../../Components/Button'; (given Button component is default export)
import { Button } from '../../Components/Button'; (if Button component is not default export)
与'P'
相同