【问题标题】:React not rendering my image from web source反应不从网络源渲染我的图像
【发布时间】:2021-01-01 19:58:38
【问题描述】:

为什么我的代码没有渲染我尝试渲染的图像?

感谢任何帮助,我已经被这个问题困扰了一段时间了。

代码:

export default class Homepage extends Component {
  constructor(props) {
    super(props)
    this.state = {
      images: [
        "https://www.clker.com/cliparts/3/m/v/Y/E/V/small-red-apple-hi.png",
      ]
    }
  }

  render() {
    return (
      <div>
        <div className="gallery">
          {this.state.images.map(({ src, index }) => (
            <img key={index} src={src} width="250px" height="250 px" />
          ))}
        </div>
      </div>
    )
  }
}

【问题讨论】:

    标签: html reactjs jsx


    【解决方案1】:

    问题在于您如何使用Array.map。如果您删除大括号,它将正常工作。

    this.state.images.map((src, index) => (
    

    更多详情,请查看documentation on MDN

    【讨论】:

    • 天哪……哈哈。我现在看起来真的很累。非常感谢您的回答!
    猜你喜欢
    • 1970-01-01
    • 2021-03-03
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    相关资源
    最近更新 更多