Reactjs 未触发axios API调用

Reactjs 未触发axios API调用,reactjs,axios,Reactjs,Axios,我有一个调用api并返回数据的组件,url如下:。但是现在api没有被触发,它返回null。我检查了浏览器的网络状态,没有api调用。有什么想法吗?我的代码如下: import React, { Component } from "react"; import axios from "axios"; class CourseDetail2 extends Component { state = { CLASS_NBR: this.props.match.params.CLASS_N

我有一个调用api并返回数据的组件,url如下:。但是现在api没有被触发,它返回null。我检查了浏览器的网络状态,没有api调用。有什么想法吗?我的代码如下:

import React, { Component } from "react";
import axios from "axios";

class CourseDetail2 extends Component {
  state = {
    CLASS_NBR: this.props.match.params.CLASS_NBR,
    course: null
  };
  componentDidMount() {
    const { CLASS_NBR } = this.state;
    this.runSearch();
  }

  runSearch = async () => {
    const response = await axios.get(
      `api/${this.props.match.params.CLASS_NBR}`
    );
    this.setState({ course: response.data });
  };
  render() {
    const course = this.state.course; //null here

    return (
      <div>
        Course Detail: CLASS NBR {this.props.match.params.CLASS_NBR} 
        ////this information is passed in through react-router Link 
        {course.SUBJECT} //null 
         CATALOGNO:{course.CATALOG_NBR}//null
      </div>
    );
  }
}
export default CourseDetail2;
import React,{Component}来自“React”;
从“axios”导入axios;
类CourseDetail2扩展了组件{
状态={
类别编号:this.props.match.params.CLASS\u编号,
课程:空
};
componentDidMount(){
const{CLASS_NBR}=this.state;
这是runSearch();
}
runSearch=async()=>{
const response=等待axios.get(
`api/${this.props.match.params.CLASS_NBR}`
);
this.setState({course:response.data});
};
render(){
const course=this.state.course;//此处为null
返回(
课程详细信息:类NBR{this.props.match.params.CLASS_NBR}
////此信息通过react路由器链路传入
{course.SUBJECT}//null
目录号:{course.CATALOG\u NBR}//null
);
}
}
导出默认的CourseDetail2;

如何使用您的
课程摘要2
?浏览器控制台中是否有错误?它是通过点击CourseList2.js视图中的链接调用的。更详细地说,另一种问这个问题的方式是,当用户键入时,它会调用axios api以获取对象详细信息,并将其显示在CourseDetail2.js组件中。如何触发api调用?是否至少使用componentDidMount调用api?否。是否需要单击事件处理程序?