I am trying to store profile thumbnail for easy access. Since I want to minimize resource consumption by eliminating the methods to fetch the image path every time the user reloads the page. Can we store image data in vuex? If so, should we do it?
I am trying to store profile thumbnail for easy access. Since I want to minimize resource consumption by eliminating the methods to fetch the image path every time the user reloads the page. Can we store image data in vuex? If so, should we do it?
Yes you can!
After the image response, pass the image to URL.createObjectURL() (Doc). This will cache the image in the browser and will give you a local image url, which you can then re-use:
const imageUrl: string = URL.createObjectURL(response.data);
if (imageUrl) {
// Update your store with an object like this:
{ id: imageId, url: imageUrl };
}
Then you can search your imageUrl[] state, where you saved this, by the id and retrieve the URL again.