Skip to content

Instantly share code, notes, and snippets.

@charlesBochet
Last active October 30, 2017 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesBochet/7ed4fa105a7bb1c7031cbf050a128271 to your computer and use it in GitHub Desktop.
Save charlesBochet/7ed4fa105a7bb1c7031cbf050a128271 to your computer and use it in GitHub Desktop.
<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