Reputation: 145
I have a JSON file that I included in my vue app. But the problem is that when I build the app, the JSON file disappears and becomes a part from a js file. How can I keep it as a JSON file after build, since I want to manipulate it?
Upvotes: 1
Views: 235
Reputation: 669
If you are using Vue CLI 3, you can place your static files in public
directory and reference them by absolute paths.
For more information you can visit the CLI documents.
public
directory.env
file in your project root. And store your base url in BASE_URL
variable. (Read More!)Add a data property containing your base URL:
data() {
return {
baseUrl: process.env.BASE_URL,
}
},
And then you can access you JSON value with an ajax call:
axios.get(this.baseUrl + 'test.json').then(response => {
console.log(response);
})
Upvotes: 1