Nan*_*Man 6 arrays image render object reactjs
我需要帮助。我一直在搜索类似的帖子,但没有一个解决我的问题(imagesPool.js)
import React from 'react';
const imagesPool = [
{ src: './images/starbucks.png'},
{ src: './images/apple.png'},
{ src: './images/mac.png'}
];
export default imagesPool;
Run Code Online (Sandbox Code Playgroud)
渲染图像(App.js):
import React from "react";
import imagesPool from './imagesPool';
const App = () => {
return (
<div>
<img src={imagesPool} />
</div>
)};
export default App;
Run Code Online (Sandbox Code Playgroud)
结果:没有显示图像
您应该循环遍历图像,因为src需要图像的字符串位置。
import imagesPool from './imagesPool';
const App = () => {
return (
<div>
{imagesPool.map((imgSrc, index) => (<img src={imgSrc.src} key={index} alt="Make sure to include a alt tag, because react might throw an error at build"/>))}
</div>
)};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8988 次 |
| 最近记录: |