如何解决获取xhr.js:184 GET http:// localhost:8600 / user-service / userbyid / [object%20Object] 400甚至url正确吗?
获取xhr.js:184以获得http:// localhost:8600 / user-service / userbyid / [object%20Object] 400 for(“ http:// localhost:8600 / user-service / userbyid /” + {使用})在哪里使用变量分配道具值? 任何我如何能够在console.log中打印“已用”值的正确方法,甚至在我使用邮递员来获取它的情况下,也能得到输出。那么为什么这个React部分没有给出输出呢?
import axios from "axios";
import { Link } from "react-router-dom";
import React,{ useEffect,useState } from "react";
import { useHistory,useParams } from "react-router-dom";
import { withStyles,makeStyles } from '@material-ui/core/styles';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableContainer from '@material-ui/core/TableContainer';
import TableHead from '@material-ui/core/TableHead';
import TableRow from '@material-ui/core/TableRow';
import Paper from '@material-ui/core/Paper';
import Button from '@material-ui/core/Button';
const StyledTableCell = withStyles((theme) => ({
head: {
backgroundColor: theme.palette.common.black,color: theme.palette.common.white,},body: {
fontSize: 14,}))(TableCell);
const StyledTableRow = withStyles((theme) => ({
root: {
'&:nth-of-type(odd)': {
backgroundColor: theme.palette.action.hover,}))(TableRow);
const useStyles = makeStyles({
table: {
minWidth: 350,});
export default function Dashboard(props) {
console.log(props);
let used = props;
const classes = useStyles();
const { id } = useParams();
const [user,setUser] = useState({
name: "",email: "",userId: 0,});
const [exams,setExam] = useState([]);
useEffect(() => {
getExams();
},[]);
const getExams = async () => {
const response = await axios.get(
"http://localhost:8500/exam-service/showexam"
);
setExam(response.data);
};
const { userId,name,email } = user;
const loadUser = async () => {
const result = await axios.get(
"http://localhost:8600/user-service/userbyid/" + {used}
);
console.log(result.data);
setUser(result.data);
};
useEffect(() => {
loadUser();
},[]);
return (
<div align="center">
<br/>
<hr/>
<br/>
<h2>ATTEMPT EXAMS</h2>
<TableContainer style={{width: 350}} component={Paper}>
<Table style={{ width: 300 }} className={classes.table} aria-label="customized table">
<TableHead>
<TableRow>
<StyledTableCell align="left">TOPIC</StyledTableCell>
<StyledTableCell align="Right">Action</StyledTableCell>
</TableRow>
</TableHead>
<TableBody>
{exams.map((exam,index) => (
<StyledTableRow>
<StyledTableCell component="th" scope="row">
{exam.title}
</StyledTableCell>
<StyledTableCell align="right">
<Link class="btn btn-primary mr-5" to={`/attemptexam/${used}/exam/${exam.qBankId}`} >Attempt</Link>
</StyledTableCell>
</StyledTableRow>
))}
</TableBody>
</Table>
</TableContainer>
</div>
);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。