我是React的新手,但遇到此错误:TypeError:this.state.list.map不是函数。
这是代码:
export default class Content extends React.Component {
constructor(props) {
super(props);
this.state = {
video: null,
list: []
};
}
...............................
images() {
return this.state.list.map((video) => {
return (
<img key={video} width="560" height="315" src={"https://img.youtube.com/vi/" + video + "/0.jpg"} onClick={() => this.openModal(video)} />
)
});
}
}
最佳答案
images()
的语法错误地绑定(bind)了this
。
试试这个
getImages = () => {
return this.state.list.map((video) => {
return (<img key={video}
width="560"
height="315"
src={"https://img.youtube.com/vi/" + video + "/0.jpg"}
onClick={() => this.openModal(video)} />
)
});
}
关于javascript - React js TypeError:this.state.list.map不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64661234/