为什么图像不加载,当试图从数组中加载时做出反应
Why Images not loading, when trying to load from an array in react
我有以下代码,我试图从阵列加载图像,如果我尝试加载单个图像它工作正常,但如果我尝试加载多个图像它不显示任何图像,我的 div test
在 dom.
import React, {Component} from 'react';
class Slider extends Component {
render() {
const myItems = [{source_image: '1.jpg'}, {source_image: '2.jpg'}, {source_image: '3.jpg'}];
return (
<div id="test">
{myItems.map(function (a) {
<img src={"images/"+a.source_image}/>
}
)}
</div>
);
}
}
export default Slider;
您在地图中忘记了 return:
{myItems.map(function (a) {
return <img src={"images/"+a.source_image}/> // here
})
}
{myItems.map(a => <img src={"images/"+a.source_image}/>)} //this is more clear, I think
我有以下代码,我试图从阵列加载图像,如果我尝试加载单个图像它工作正常,但如果我尝试加载多个图像它不显示任何图像,我的 div test
在 dom.
import React, {Component} from 'react';
class Slider extends Component {
render() {
const myItems = [{source_image: '1.jpg'}, {source_image: '2.jpg'}, {source_image: '3.jpg'}];
return (
<div id="test">
{myItems.map(function (a) {
<img src={"images/"+a.source_image}/>
}
)}
</div>
);
}
}
export default Slider;
您在地图中忘记了 return:
{myItems.map(function (a) {
return <img src={"images/"+a.source_image}/> // here
})
}
{myItems.map(a => <img src={"images/"+a.source_image}/>)} //this is more clear, I think