I am practicing fetch Api, and trying to get the data of projects.json file in my vue-cli project and to show it on console.
Project architecture:
src/views/Projects.vue
src/assets/projects.json
Projects.vue in created method we fetch the json data
<template>
<div>
<h1>Hello WOrld</h1>
</div>
</template>
<script>
export default {
name: "projects",
created() {
fetch("../assets/projects.json")
.then(res => res.json())
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
}
};
</script>
when load the component Syntax Error is shown.
SyntaxError: Unexpected token < in JSON at position 0
projects.json contains just the basics
{
"projects": [
{
"id": 1,
"title": "pie station"
},
{
"id": 1,
"title": "automate dryer"
}
],
"profile": {
"name": "someaone"
}
}
How can I show in console the content of my .json file using fetch Api?