Complete the code to run a function before the component mounts.
<script setup> import { onBeforeMount } from 'vue' onBeforeMount(() => { console.log([1]) }) </script>
The onBeforeMount hook runs before the component mounts. You can put any code inside the function, like logging a message.
Complete the code to run cleanup code before the component unmounts.
<script setup> import { onBeforeUnmount } from 'vue' onBeforeUnmount(() => { [1]('Cleaning up before unmount') }) </script>
The onBeforeUnmount hook runs just before the component is removed. It's a good place to clean up resources or log messages.
Fix the error in the lifecycle hook import statement.
<script setup> import { [1] } from 'vue' [1](() => { console.log('Before mount') }) </script>
The correct Vue lifecycle hook name to run code before mounting is onBeforeMount. The others are either incorrect or do not exist as imports.
Fill both blanks to log messages before mount and before unmount.
<script setup> import { [1], [2] } from 'vue' [1](() => console.log('Starting mount')) [2](() => console.log('Starting unmount')) </script>
Use onBeforeMount to run code before mounting and onBeforeUnmount before unmounting.
Fill all three blanks to create a component that logs before mount, before unmount, and after mount.
<script setup> import { [1], [2], [3] } from 'vue' [1](() => console.log('Before mount')) [3](() => console.log('Mounted')) [2](() => console.log('Before unmount')) </script>
This code uses onBeforeMount to log before mounting, onBeforeUnmount before unmounting, and onMounted after the component mounts.