localstorage.js 310 B

12345678910111213141516
  1. const db = {
  2. save(key, value) {
  3. localStorage.setItem(key, JSON.stringify(value))
  4. },
  5. get(key, defaultValue = {}) {
  6. return JSON.parse(localStorage.getItem(key)) || defaultValue
  7. },
  8. remove(key) {
  9. localStorage.removeItem(key)
  10. },
  11. clear() {
  12. localStorage.clear()
  13. }
  14. }
  15. export default db