【发布时间】:2020-09-21 02:40:55
【问题描述】:
以下是我在调用 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 的响应。谁能帮我解决这个问题。我需要做一个模型课吗?并在服务方法中返回它作为响应?
【问题讨论】:
标签: javascript reactjs typescript axios