HDTuto.com

How to call function on page load in Vue JS?


If you are finding way to run function when page load then, this tutorial will help to do that. sometimes you may require to write some code or function code on vue js and you must require to load when your page is load. so we can do it using created parameter in vue js. So let's just see bellow full example code.

index.html

<!DOCTYPE html>

<html>

<head>

<title>How to call function on page load in Vue JS?- HDTuto.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>

I hope you found your solution...




June 24, 2018 | Category : Vue.js
Related Posts