Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在reactjs中获取axios调用_Javascript_Reactjs_Typescript_Axios - Fatal编程技术网

Javascript 在reactjs中获取axios调用

Javascript 在reactjs中获取axios调用,javascript,reactjs,typescript,axios,Javascript,Reactjs,Typescript,Axios,下面是我在执行get呼叫后得到的响应: {     "id": “12345”,     “details”: {         “name”: “sample doc”,         “market: “sample market”     } } 我的服务方式: ENDPOINTS = { product: "/market/product", } getDetails( id: string ): Promise<

下面是我在执行get呼叫后得到的响应:

{
    "id": “12345”,
    “details”: {
        “name”: “sample doc”,
        “market: “sample market”
    }
}
我的服务方式:

ENDPOINTS = {
    product: "/market/product", 
}
     getDetails(
            id: string
          ): Promise<{
            id: string;
          }> {
            const url = `${this.ENDPOINTS.PRODUCT}/${id}/name`;
            return http
              .get(url)
              .then((response) => {
                return response.data;
              })
              .catch((error) => {
                throw error;
              });
          }
我的组件方法:

getTestingDone = () => {
    this.sampleService
      .getDetails(
        this.props.product.id,
      )
      .then((response) => {
        this.setState({
        });
      })
      .catch((error) => {
        console.log(error);
      });
  };

        <TextInput
          labelText="name"
          type="text"
          name="keyname"
          value = {name}
        />
我想在此输入字段中打印响应。不确定如何从服务器获取对UI的响应。有人能帮我吗?我需要做一个模型课吗?并在服务方法中返回它作为响应?

constructor{ 此.state={ 姓名: } } getTestingDone==>{ 这是我的样品服务 .GetDetails此.props.product.id 。然后{详细信息:{name}}=>{ this.setStatestate=>{…state,name}; } } 渲染{ const{name}=this.state; 回来 } 建造师{ 此.state={ 姓名: } } getTestingDone==>{ 这是我的样品服务 .GetDetails此.props.product.id 。然后{详细信息:{name}}=>{ this.setStatestate=>{…state,name}; } } 渲染{ const{name}=this.state; 回来 }
这是上述问题的正确答案:

constructor(){
    this.state = {
     details: {
          name: "",
          market: "",
        }
    }

    getTestingDone = () => {
      this.sampleService
        .getDetails(this.props.product.id)
        then((response) => {
            this.setState({
              credentials: response.credentials,
            });
        })

      return <TextInput
        labelText="name"
        type="text"
        name="keyname"
        value = {this.state.details.name}/>
    }
    }

这是上述问题的正确答案:

constructor(){
    this.state = {
     details: {
          name: "",
          market: "",
        }
    }

    getTestingDone = () => {
      this.sampleService
        .getDetails(this.props.product.id)
        then((response) => {
            this.setState({
              credentials: response.credentials,
            });
        })

      return <TextInput
        labelText="name"
        type="text"
        name="keyname"
        value = {this.state.details.name}/>
    }
    }

我会从那里得到你发送的详细信息。然后。它是一个模型类吗?返回response.data;然后,getDetails函数返回json响应,然后{details:{name}}销毁我没有得到的模型。请您详细说明一下,我将从哪里获得您发送的详细信息。然后。它是一个模型类吗?返回response.data;然后,getDetails函数返回json响应,然后{details:{name}}销毁模型。我没有得到它。您能详细说明一下吗