【发布时间】:2021-03-25 18:00:59
【问题描述】:
我正在尝试从我的 api 获取 componentValue,但它不起作用。我在终端或控制台中没有收到任何错误。
这是我的 api 提供的 json:
[
{
id: 100,
componentName: "bp",
componentValue: "120/80",
measuredDateTime: null
},
{
id: 102,
componentName: "bp",
componentValue: "120/80",
measuredDateTime: null
},
{
id: 107,
componentName: "bp",
componentValue: "50/60",
measuredDateTime: null
},
{
id: 30,
componentName: "bp",
componentValue: "90/149",
measuredDateTime: "2018-03-19T18:34:24.000+00:00"
}
]
这是我的反应代码:
import React from 'react';
import axios from 'axios';
class ChartGenerator extends React.Component{
state={
clinicalData:[]
}
componentDidMount(){
axios.get("http://localhost:8080/clinicalservices/api/clinicals/1/bp").then(res=>{
this.setState(res.data);
})
}
render(){
return (<div>
<h2>Clinical Report:</h2>
{this.state.clinicalData.map((item,index)=>(
<p key={index}>{item.componentValue}</p>
))}
</div>);
}
}
export default ChartGenerator;
我尝试了所有方法,但没有成功! 如果你知道什么请帮助我!
【问题讨论】: