IAC*_*C93 6 import components reactjs
我目前有我的项目文件夹
app
- node_modules
- public
- src
- Assets
- Components
- profiles
- homepage
- gulpfile
Run Code Online (Sandbox Code Playgroud)
在我的主页组件中,我试图将整个配置文件目录导入到这样的对象中(根据需要动态加载每个组件,但不会加载所有组件)
import Comps from '../profiles/';
Run Code Online (Sandbox Code Playgroud)
还
import * as Comps from '../profiles/;
Run Code Online (Sandbox Code Playgroud)
但我在编译器中收到一个错误,提示找不到模块:无法解析 '../profile.
我想说明一下,profiles 是一个包含组件的文件夹,我想在我的 app.js 文件中选择所有要动态调用的组件。
为什么会这样?
ba5*_*eem -1
你是否在一个 js 文件中有多个组件,如果是的话 - 你可以这样做:
配置文件.js:
import React from 'react';
export const ViewA = () => {
return( <div>A VIEW</div>)
};
export const ViewB = () => {
return( <div>B VIEW</div>)
};
export const ViewC = () => {
return( <div>C VIEW</div>)
};
export const ViewD = () => {
return( <div>D VIEW</div>)
};
Run Code Online (Sandbox Code Playgroud)
应用程序.js:
import React, { Component, PropTypes } from 'react'
import * as Profiles from './Profiles';
class App extends Component {
render(){
return (
<div>
<Profiles.ViewA/>
<Profiles.ViewB/>
<Profiles.ViewC/>
</div>
)
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12582 次 |
| 最近记录: |