[Vuejs]-Keep getting [Object Object] in hybrid app Javascript

4๐Ÿ‘

โœ…

So, what happens, is that localStorage stores STRINGS, not objects.

When you save your item to localStorage, first convert it to a string, then parse it from a string when you retrieve it.

localStorage.setItem('a', {b:'c',d:'e'})

localStorage.getItem('a')  // "[object Object]" <- note the quotes!

localStorage.setItem('a', JSON.stringify({b:'c',d:'e'}))

JSON.parse(localStorage.getItem('a')) // {b: "c", d: "e"}
๐Ÿ‘คuser1211530

Leave a comment