1 min read
Vue Tip: Lifecycle Hooks for Debugging
Vue provides two lifecycle hooks that we can use for debugging purposes.
Ask my AI assistant
Vue provides two lifecycle hooks that we can use for debugging purposes: onRenderTracked and onRenderTriggered.
These hooks are development-mode-only and not called during server-side rendering.
onRenderTracked
Registers a debug hook to be called when a reactive dependency has been tracked by the component's render effect:
<script setup>
import { ref, onRenderTracked } from 'vue'
const count = ref(0)
const count2 = ref(0)
// Called twice, once for count and once for count2
onRenderTracked((event) => {
console.log(event)
})
</script>
onRenderTriggered
Registers a debug hook to be called when a reactive dependency triggers the component's render effect to be re-run:
<script setup>
import { ref, onRenderTriggered } from 'vue'
const count = ref(0)
// Called when we update count
onRenderTriggered((event) => {
console.log(event)
})
</script>