1 | initial version |
There are different ways to invoke a function after the page has finished loading in Vue.js:
mounted
lifecycle hook: This hook is called after the component has been mounted to the DOM. You can define the function inside the mounted hook like this:mounted() {
// invoke your function here
}
created
lifecycle hook: This hook is called before the component is mounted to the DOM, but after the component has been initialized. You can define the function inside the created hook like this:created() {
// invoke your function here
}
v-once
directive: You can use the v-once
directive to render an element only once and then prevent it from re-rendering. You can add the function call to this element like this:<div v-once>
<!-- your HTML code here -->
{{ yourFunction() }}
</div>
You can choose the method which suits your requirement the most.