[Vuejs]-Vuejs use fetch Api get data of projects.json: Unexpected token < in JSON at position 0

1👍

Look for the network tab in the console, you’ll probably notice that your fetch call is returning a 404 html page. The server is most likely not serving the package.json but that depends on your setup. (you normally wouldn’t want to serve it anyway)

Are you running a default vue cli environment with an npm run serve? If so you can add a json file in the assets dir, this should be served normally and it can be fetched at /assets/{insert the rest of the path here}.

EDIT

Say you have projects.json in the assets dir like you mentioned in the comments you should be able to access it with fetch("/assets/projects.json")

👤red-X

Leave a comment