I have data that does not need a live binding and comes from a remote source. This is a JSON file generated by the server from some admin, and may be updated occasionally.
I have a Vue instance I want use that data in as a custom option to avoid unnecessary reactivity binding.
I cannot import into the .vue file itself in the build as it won't be built every time the data changes on the server.
If I'm loading each file (the store.json and main.js) I have a race condition here where the data might not yet be loaded when the main.js is loaded, and therefore my custom option would be empty.
Is there a Vue pattern for not initializing until some data is present?
Tried:
export default {
store: "",
mounted(){
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(){
if (httpRequest.readyState === XMLHttpRequest.DONE) {
this.store = JSON.parse(httpRequest.responseText);
console.log(this.store) //shows the expected return, but obviously no update to the page
}
}
httpRequest.open("GET", "/store.json", true);
httpRequest.send();
}
};