What is the way to solve Axios GET request 404 error in Vue?
P粉738046172
2023-08-30 00:23:34
<p>I want to display questions with related answers. Unfortunately, if I load a separate <code>QuestionPage</code>, it does not show all the answers. This is because I found a logic error in the <code>./components/Answers.vue</code> component. </p>
<p>I think the problem is in my <code>fetch()</code> function, where the endpoint link is undefined (screenshot of console error https://prnt.sc/198ebdx)< /p>
<p>This Answers component is used in QuestionPage. I think the <code>Question</code> component does not reference the <code>Answer</code> component correctly. </p>
In the
QuestionPage.vue
component, your<answers :question="question"></answers>
should have av-if= "question.id"
to prevent loading the component in case thequestion
defined in thedata()
function does not exist.explain
The error reported in the console is because an undefined variable was used in your HTTP request.
View your
Answers.vue
component, there is the following code in thecreated
function:This question ID refers to the Props/Data structure in the same
Answers.vue
:In your
QuestionPage.vue
component, you passquestion
as prop to theAnswers.vue
component. However, this variable may be undefined. You should first check the result of this functionIf the function has no results, make sure your
slug
prop is correct and handled by the backend.