我能够获取数据,因为它只是我可以从控制台看到的一条记录,但由于我在代码中写错了一些东西,我无法显示...但我能够在控制台中看到获取的数据数据类似于这样的数据:Array(4) 0: "Admin ID : 602" 1: "Name : Raj" 2: "Admin pin : 131195" 3: "PHONE NUMBER :9742894200"
import Axios from 'axios'
import React, { Component } from 'react'
class Admin extends Component{
constructor(props){
super(props)
this.state={
posts: []
}
}
componentDidMount(){
const username = this.props.location.username;
Axios.get('http://localhost:9000/admin-service/admin/'+username)
.then(response => {
this.setState({ posts : response.data })
console.log(response);
})
.catch(error => {
console.log(error);
})
}
render(){
const { posts } = this.state
return(
<div>
<h2>USER DASHBOARD:</h2>
{
posts.length ?
posts.map(admin => <div key={admin.adminId}>{admin.adminId}</div>) :
null
}
</div>
)
}
}
export default Admin
犯罪嫌疑人X
宝慕林4294392
蝴蝶刀刀
相关分类