I'm building a webapp that requires a JSON file as data. The person using my app in their website should be able to pass in a JSON file hosted on their server so that my app can read it.
In development, I just used import mydata from "./mydata.json"
, but this won't work in production. I tried to have a computed property that returns require (this.publicPath + this.datapath)
(where this.publicPath
is process.env.BASE_URL
, but it's not able to find the file (if it's relevant, I'm using vue-cli to build).
The structure of my app is that I have a wrapper App.vue
and then the main component, main-component.vue
(so that I can pass a prop containing data to the main component).
What's the best way to do this? I've tried using a <script>
tag in index.html
, but apparently that's not supported with JSON. I don't want to use other libraries like jQuery.
(I'm thinking that I could have the user just import their file with the ES6 syntax by creating a new Vue component/app, but I'm not sure how to do that in pure HTML).