Skip to content

Instantly share code, notes, and snippets.

@maksnester
Last active March 12, 2019 09:04
Show Gist options
  • Save maksnester/4439554dc7f368a72bfefa5937408135 to your computer and use it in GitHub Desktop.
Save maksnester/4439554dc7f368a72bfefa5937408135 to your computer and use it in GitHub Desktop.
Vue component with common own and vue-router life cycle hooks
<template><h1>It works</h1></template>
<script>
export default {
name: 'MyComponent',
beforeRouteEnter(to, from, next) {
console.debug('beforeRouteEnter: ', to)
// no `this` available here
next((vm) => {
vm.dummyField = 'dummyValue'
})
},
beforeRouteUpdate(to, from, next) {
console.debug('beforeRouteUpdate: ', to)
next()
},
beforeRouteLeave(to, from, next) {
console.debug('beforeRouteLeave: from', from, 'to', to)
next()
},
activated() {
console.debug('activated', this.$vnode.tag)
},
deactivated() {
console.debug('deactivated', this.$vnode.tag)
},
created() {
console.debug('created', this.$vnode.tag)
},
mounted() {
console.debug('mounted', this.$vnode.tag)
},
destroyed() {
console.debug('destroyed')
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment