base_ui/hooks/hooks_component.md
2025-02-01 13:04:55 +03:30

2.3 KiB

  1. onBeforeMount This hook is called before the component is mounted to the DOM. It can be used to perform tasks such as:

    Initializing the component
    Setting up event listeners
    Logging component mount
    

import { onBeforeMount } from 'vue'

export function useMyHook() { onBeforeMount(() => { console.log('Component about to mount') }) }

  1. onMounted This hook is called when the component is mounted to the DOM. It can be used to perform tasks such as:

    Initializing the component
    Setting up event listeners
    Logging component mount
    

    import { onMounted } from 'vue'

export function useMyHook() { onMounted(() => { console.log('Component mounted') }) }

  1. onBeforeUpdate This hook is called before the component is updated. It can be used to perform tasks such as:

    Updating the component's state
    Handling events
    Logging component update
    

    import { onBeforeUpdate } from 'vue'

export function useMyHook() { onBeforeUpdate(() => { console.log('Component about to update') }) }

  1. onUpdated This hook is called when the component is updated. It can be used to perform tasks such as:

    Updating the component's state
    Handling events
    Logging component update
    

    import { onUpdated } from 'vue'

export function useMyHook() { onUpdated(() => { console.log('Component updated') }) }

  1. onBeforeUnmount This hook is called before the component is unmounted from the DOM. It can be used to perform tasks such as:

    Cleaning up resources
    Logging component unmount
    Handling errors
    

    import { onBeforeUnmount } from 'vue'

export function useMyHook() { onBeforeUnmount(() => { console.log('Component about to unmount') }) }

  1. onUnmounted This hook is called when the component is unmounted from the DOM. It can be used to perform tasks such as:

    Cleaning up resources
    Logging component unmount
    Handling errors
    

    import { onUnmounted } from 'vue'

export function useMyHook() { onUnmounted(() => { console.log('Component unmounted') }) }