import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
import videoDetails from './components/listvideos';
class YoutubeApp extends Component {
constructor(props){
super(props)
this.state = {
videos:[]
};
this.apiCall('surfing');
}
apiCall(term){
const params = {
part: 'snippet',
key:APP_KEY,
q:term,
type: 'video'
};
axios.get(APP_URL, { params: params})
.then(function(response) {
this.setState({
videos:response
})
})
.catch(function(error) {
console.error(error);
});
}
render(){
return (
<div>
<videoDetails/>
</div>
)
}
}
ReactDOM.render(
<YoutubeApp/>,
document.getElementById('app')
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react-dom.min.js"></script>
<div id="app">
</div>
嗨,我正在尝试制作一个用于练习的 youtube 克隆我是这方面的初学者,但我不明白为什么 react 上的状态给我带来了问题 我正在尝试将状态设置为我的视频数组,以便我可以将其传递给其他组件我没有包含 api 密钥或 url,但它的可读性很强,这是错误 {Cannot read property 'setState' of undefined}