How to trigger a method at page load in vuejs?

2020-05-25 04:09发布

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

2条回答
霸刀☆藐视天下
2楼-- · 2020-05-25 04:47

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 */
        }
     },
})
查看更多
聊天终结者
3楼-- · 2020-05-25 04:54

This syntax is working fine:

export default {
    mounted() {
      this.myMethod()
    },
}
查看更多
登录 后发表回答