通过Axios帖子对参数进行反应



我想使用Axios.post将params传递到服务器,但它无法处理404错误,有什么想法吗??

代码:

function Movie() {
const { index } = useParams(); // get index from path /movie/:index
const [movie, setMovie] = useState([]);
useEffect(() => {
Axios.post("http://localhost:3001/movie", {
params: { id: index },
})
.then((response) => {
setMovie(response.data);
})
.catch((err) => {
console.log(err);
});
}, []);
return (
<body>
abc
{index}
{movie.id}
</body>
);
}

服务器:

app.post('/movie', async (req, res)=>{
let id= req.params.id;
let movie=[];
movie.push(id);
res.send(movie); 
});

404错误表示在API上找不到路径/movie。也许要确保服务器上的路由命名正确。

最新更新