Consider this scenario - I have a Vue.js component where I need to display the name of a user based on their ID. The only information I have is the user's ID. However, I also have a JSON file URL that contains all the user objects with their names and IDs. This allows me to retrieve the user's name by matching their ID.
Currently, I am making a GET request to the JSON file URL when the Vue.js component is mounted. Once the request is successful, I store the response and use a function to retrieve the user's name based on their ID.
However, I have encountered some issues with this approach:
- Every time the component is reloaded, a new GET request is made to the JSON file URL.
- I can only access the response from the GET request within this specific component. I need to access the JSON data from other components as well, which would require duplicate GET requests to the same JSON file.
I believe storing the JSON response in VUEX would be a better solution as it would allow me to access the data from any component. However, I am unsure where to place the GET request to the JSON file in this case.
Is there a specific location in Vue.js where I can initiate the GET request so that it is executed every time the Vue.js application is launched, but not more than once?