显示来自 .map 数组的图像(反应)

Japesc20

        setForecast(res2.data.list.map(item => [
          <div className="each_data_point">
            <li className="date_time" key={item.dt_txt}>{`Date & Time: ${item.dt_txt}`}</li>,
            <img className="icon" key={item.weather[0].icon}>{`https://openweathermap.org/img/w/${item.weather[0].icon}.png`}</img>,
            <li className="main_temp" key={item.main.temp}>{`Temp: ${item.main.temp}`}</li>
          </div>
        ]
        ))
        
        
        ......
        
        
        return (
        <div>
        <div className="five_day_forecast">
            <div className="temp_body">
            
            // Display here with Date/Time & Main Temp.
                <p>{forecast}</p>

            </div>
            </div>

是否可以在 React 中从 array.map() 渲染图像。当我运行它时,DOM 完全清除为白屏。

越南的

srcimg标签中使用来渲染图像

 <img className="icon" key={item.weather[0].icon} src={`https://openweathermap.org/img/w/${item.weather[0].icon}.png`} />

div而是把钥匙放在孩子们身上。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章