您应该分离对另一个方法的api调用,并在搜索时调用它
constructor(props) {
super(props);
this.state = {
movies: [],
searchString: 'bing bang',
boolian: true,
};
}
showSearch = async (searchString) => {
try {
const response = await axios.get(`http://api.tvmaze.com/search/shows?q=${searchString}`);
this.setState({ movies: response.data });
} catch (error) {
console.log(error);
}
}
async componentDidMount() {
this.showSearch(this.state.searchString)
}
按下搜索按钮,您可以按
this.showSearch(searchString)