Javascript 在reactjs中获取axios调用
下面是我在执行get呼叫后得到的响应: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<
{
"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}}销毁模型。我没有得到它。您能详细说明一下吗