Answer the question
In order to leave comments, you need to log in
How to parse json in vue cli?
It is necessary to transfer data from the local json file to the application, I tried to do it like this:
fetch('@/todo.JSON')
.then(result => result.json())
.then(data => {
this.todos = data.contents;
})
Answer the question
In order to leave comments, you need to log in
Throw your JSON in public
and then just fetch('/json_name.json')
.
Because fetch doesn't understand the address of your file, it's not clear to it what @ is.
@ is just an alias in vue cli for local development, which will then be converted to the normal path. You can't do ajax requests like this. Be sure to specify the path to the file.
fetch('../../../todo.JSON')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question