Home  >  Article  >  Web Front-end  >  How to get local json file in Vue-cli project

How to get local json file in Vue-cli project

php中世界最好的语言
php中世界最好的语言Original
2018-03-28 15:18:582070browse

This time I will show you how the Vue-cli project obtains the local json file. What are the precautions for the Vue-cli project to obtain the local json file. The following is a practical case. Let’s take a look. .

In my vue demo project, I want to add some json data locally, write it to a json file, obtain it through an asynchronous request, and then load the data.

axios.get('http://localhost:8080/datas/json')

However, in this process, my access is always 404. After checking, I found that in the project built on the basis of vue-cli, only the static directory is vue The static data folder exposed by -cli can be accessed normally by the pictures I placed under static. I created a new datas directory in the same level directory as static and put the json file When I put it in the datas directory, the request is always 404. When I put the json file in the static directory, it can be accessed normally.

This feature must be remembered:

The static directory is the static folder exposed by vue-cli, and all static data is It should be placed in the static directory! !

The above example of the Vue-cli project obtaining local json file data is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to modify the value in vue request data

How to assign $set to an array in vue.js renew

The above is the detailed content of How to get local json file in Vue-cli project. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn