I am relatively new to Vue, so please bear with me as I may not have all the knowledge in this area.
Within one of my child components
(Product_Collection.vue)
, I am making an axios request to retrieve products from my Shopify store using their GraphQL API:data: () => { return { products: null } }, methods: { getProducts: function(){ // 1. axios code here... // 2. ...then assign result to "this.products" data property } }
The products are displayed as thumbnails (let's say there are 10 t-shirts). When I click on a product, I want to view it in more detail with additional information and images, similar to the experience on Amazon.
The product is then shown individually in a
Product_Single.vue
component. So far, everything seems to be working fine.
However, here lies the issue...
- When I navigate back to the products page
(Product_Collection.vue)
(the page displaying the 10 t-shirts), the axios request to the Shopify API is triggered again, causing the component to be re-rendered from scratch.
My question is how can I instruct Vue to refrain from fetching data from the Shopify API every time the component is rendered? Thank you for your help.