[Vuejs]-Vuejs data in the array you refreshed page is empty

0👍

You can only do that if you store your data to the localStorage, sessionStorage or cookies otherwise all the data will be eliminated on the refresh.

Here is the official documentation from Vue.js on how to store data on the client-side.
Basically instead of pushing the data to a variable, you have to save it on the client-side, let’s say on localStorage something like the code below:

addToCart: function(value){
   const cart = localStorage.getItem('cart');
   cart.push(value);
   localStorage.setItem('cart', cart);
}

Be careful though, sessionStorage, localStorage, and cookies have some differences not only on their API but on their use as well, check this out for more

Leave a comment