在使用的react版本如下:
// ...
function HouseDetail() {
const [houseinfo, setHouseinfo] = useState({
houseImg: [],
// ...
}
})
// ...
// 渲染轮播图结构
function renderSwipers() {
const { houseImg } = houseinfo
return houseImg.map(item => {
const val = /^[\s\S]*(.jpg)$/
if(val.test(item)==false) {
return
}
return (
<Swiper.Item key={item}>
<a href="https://www.baidu.com">
<img src={BASE_URL + item} alt="" />
a>
Swiper.Item>
)
})
}
// ...
return (
// ...
{/* 轮播图 */}
slides}>
{!isloading ? (
<Swiper indicatorProps={{
color: 'white',
}} defaultIndex={0} loop autoplay infinite autoplayInterval={5000}>
{renderSwipers()}
Swiper>
) : (
''
)}
// ...
}
// ...
chrome浏览器显示提示:
人家不是说了吗最少一个子元素,houseImg开始是空的时候,渲染 然后抱一个警告 有什么问题?