Moved localstorage parser to mixin

This commit is contained in:
Joel Collins 2019-05-10 09:32:41 +01:00
parent f87e6d55e9
commit 29ad537aad
2 changed files with 21 additions and 10 deletions

View file

@ -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);
}
}