在使用的react版本:
export default class HouseDetail extends Component {
// ...
// 渲染轮播图结构
renderSwipers() {
const {
houseInfo: { houseImg }
} = this.state
return houseImg.map(item => (<Swiper.Item>
<a key={item} href="https://www.baidu.com">
<img src={BASE_URL + item} alt="" />
a>
Swiper.Item>
))
}
// ...
return (
// ...
<div className={styles.slides}>
{!isLoading ? (
<Swiper indicatorProps={{
color: 'white',
}} defaultIndex={0} loop autoplay infinite autoplayInterval={5000}>
{this.renderSwipers()}
Swiper>
) : (
''
)}
div>
)
// ...
}
目前效果如下,轮播图及其底部几个小原点没有显示出来,且chrome浏览器报错:
警告是:swiper下面必须有chile。建议你先打印出你遍历的houseImg是否正确
swiper 没有子元素 呗 。说明数据问题 。你要写死一个 他就不会 有了 。