E
E
Erik21212018-11-27 21:44:38
JavaScript
Erik2121, 2018-11-27 21:44:38

Why is data being erased from localStorage?

Hello, I ran into such a problem, I have a shopping cart on Vue.js without Node, just like a library, the fact is that I store product data in localStorage:

[
{id: "16", title: "Arcturus", url: "arcturus",…},
{id: "63", title: "Alamo Frills", url: "alamo-frills",…},
{id: "88", title: "Dolores' Raspberry Sundae", url: "dolores-raspberry-sundae",…},
{id: "34", title: "Kei-Yoki", url: "kei-yoki",…}
]

For convenient work with localStorage, I took the store library. The problem is definitely not because of her, without her it was the same. There is a cart
variable :
let app = new Vue({
  el: '#app',
  data: {
         // если нет cart в localStorage, то будет пустой массив
          cart: !store.has('cart') ? [] : store.get('cart'), 
          qty: 1
        },
       ...
});

Then everything works fine, but why when I go to the site for the first time and add products to localStorage and, for example, refresh the page, everything disappears ((and if I do the same for the second time, everything is saved normally and does not disappear, tell me what could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question