Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a method at page load in vuejs?

How can I trigger a method at page load like tab?
for example:

<div id='wraper'>  <!-- div id menu not load -->  <div id="menu">    <a href='#'>test</a>    <a href='#'>test</a>    <a href='#'>test</a>  </div>    <!-- load this content  -->  <div id="content">  konten  </div>      </div>  

Thanks

like image 753
b4dQuetions Avatar asked Jan 28 '16 14:01

b4dQuetions


People also ask

How do you call a method on page load in Vue?

We can call a Vue. js method on page load by calling it in the beforeMount component hook. We can also make a method run on page load by calling it in the created hook. And we can do the same in the mounted hook.

Which lifecycle function is first called when a Vue app is loaded in the DOM?

beforeCreate() This is the very first lifecycle hook that gets called in Vue JS, it gets called immediately after the Vue instance has been initialized.


1 Answers

For vue >= 2.0 use mounted and for previous version use ready.

vm=new Vue({   el:"#app",   mounted:function(){         this.method1() //method1 will execute at pageload   },   methods:{         method1:function(){               /* your logic */         }      }, }) 
like image 63
Ashutosh Raj Avatar answered Sep 17 '22 04:09

Ashutosh Raj