[Vuejs]-How do I save a hashmap to localstorage using Vue?

3👍

According to the (doc), the storage value is a DOMString, and it

corresponds exactly to the JavaScript primitive String type

So if you want to save a hashmap, convert it to string with JSON.stringify and setItem, and when you getItem, parse it back to hashmap with JSON.parse

// set
localStorage.setItem('summaries', JSON.stringify(this.summaries))

// get
this.summaries = JSON.parse(localStorage.getItem('summaries'))
👤hgb123

Leave a comment