How to call function on load in Vue JS?

19-Mar-2021

.

Admin

How to call function on load in Vue JS?

Hi Guys,

Today, I will learn you how to call a function on load in Vue JS. We will show an example of Vue js call a function on load example. we will run function on page load Vue application.

we mostly require to call method on page load in our application. so you want to call function in the vue.js app then you can do it using the created option in Vue js. So I will give a full example so you can check it out.

Example


<!DOCTYPE html>

<html>

<head>

<title>Vue JS call function on load Example - ItSolutionStuff.com</title>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>

</head>

<body>

<div id="app">

{{ message }}

</div>

<script type="text/javascript">

var app = new Vue({

el: '#app',

data: {

message: 'Hello Vue!'

},

methods:{

myFunctionOnLoad: function() {

console.log('call on load...');

}

},

created: function(){

this.myFunctionOnLoad()

}

})

</script>

</body>

</html>

it will help you....

#Vue.Js

#Vue