【发布时间】:2017-03-31 14:38:56
【问题描述】:
我正在编写一个基于 react.js 的网站。我希望背景图像在我的索引页面中自动滑动,并从Ant Design 导入元素{carousel},它实现了如何使用carousel。我有将路由到每个组件的代码。现在,我想知道如何将 {carousel} 插入索引页面。我有以下代码:
/* eslint no-unused-vars: "off" */
import React from 'react';
import { render } from 'react-dom';
import { Router, Route, browserHistory } from 'react-router'
import Root from './Root/Root'
import MainLayout from './MainLayout/MainLayout'
import MyRoot from './MyRoot/MyRoot'
import CreateNew from './CreateNew/CreateNew'
import './index.css'
import { Carousel } from 'antd';
// see https://github.com/ReactTraining/react-router
render((
// <Carousel autoplay>
// <div><image>1</image></div>
// <div><image>2</image></div>
// <div><image>3</image></div>
// <div><image>4</image></div>
// </Carousel>, mountNode;
<Router history={browserHistory}>
<Route component={MainLayout}>
<Route path="/" component={Root}/>
<Route path="/myitinerary" component={MyRoot}/>
<Route path="/createnew" component={CreateNew}/>
</Route>
</Router>
), document.getElementById('root'));
老实说,我不知道我为什么这样做,我只是在猜测。还是我需要创建另一个组件来保存轮播信息?或者有没有其他容易理解的方法来做到这一点。非常感谢!
【问题讨论】:
-
我假设您将它放入 MainLayout 组件中,就像您在其中的方式一样(当然未注释)
-
@SamiKuhmonen 感谢您的建议,但无论如何它不起作用。
-
@XiufenXu 你看到我的回答了吗?对你有帮助吗?