Moved localstorage parser to mixin
This commit is contained in:
parent
f87e6d55e9
commit
29ad537aad
2 changed files with 21 additions and 10 deletions
17
src/main.js
17
src/main.js
|
|
@ -67,6 +67,23 @@ Vue.mixin({
|
|||
}
|
||||
this.$store.dispatch('errorState', errormsg);
|
||||
UIkit.notification({message: `<span uk-icon=\'icon: warning\'></span> ${errormsg}`, status: 'danger'})
|
||||
},
|
||||
|
||||
getLocalStorageObj: function(keyName) {
|
||||
if (localStorage.getItem(keyName)) {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem(keyName))
|
||||
} catch(e) {
|
||||
console.log("Malformed entry. Removing from localStorage")
|
||||
localStorage.removeItem(keyName)
|
||||
return null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
setLocalStorageObj: function(keyName, object) {
|
||||
const parsed = JSON.stringify(object)
|
||||
localStorage.setItem(keyName, parsed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue