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
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.
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.
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 */ } }, })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With