[Vuejs]-Execute a function when the page (component) loads in Vue 3

2👍

If you want to execute a function within your component as soon as the component is loaded, you can use the lifecycle hook onMounted and execute your function within it.

For example:

<script setup>
import { onMounted } from "vue"
import { someFunction } from "./js/allowFunctions.js"

onMounted(() => {
  someFunction()
})
</script>
👤Alex

Leave a comment