获取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 (将#修改为@)