Last active
October 30, 2017 22:06
-
-
Save charlesBochet/7ed4fa105a7bb1c7031cbf050a128271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
export default { | |
methods: { | |
displayDetails (id) { | |
this.$router.push({name: 'detail', params: { id: id }}) | |
}, | |
getCats () { | |
if (navigator.onLine) { | |
this.saveCatsToCache() | |
return this.$root.cat | |
} else { | |
return JSON.parse(localStorage.getItem('cats')) | |
} | |
}, | |
saveCatsToCache () { | |
this.$root.$firebaseRefs.cat.orderByChild('created_at').once('value', (snapchot) => { | |
let cachedCats = [] | |
snapchot.forEach((catSnapchot) => { | |
let cachedCat = catSnapchot.val() | |
cachedCat['.key'] = catSnapchot.key | |
cachedCats.push(cachedCat) | |
}) | |
localStorage.setItem('cats', JSON.stringify(cachedCats)) | |
}) | |
} | |
}, | |
mounted () { | |
this.saveCatsToCache() | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment