I use vue-router and jQuery in the template,when i switch router $(document).ready() is failure

后端 未结 2 1054
感情败类
感情败类 2021-01-24 06:36

I do not know jQuery in vue correct usage. When I refresh page, $(document).ready() has a role. But when I switch the page through vue-router, $(document).rea

2条回答
  •  一生所求
    2021-01-24 06:52

    Instead of relying on $(document).ready() in a vue webapp, you can use one of the lifecycle hooks for this purpose. You can try using mounted as it comes pretty close to $(document).ready():

    Called after the instance has just been mounted where el is replaced by the newly created vm.$el. If the root instance is mounted to an in-document element, vm.$el will also be in-document when mounted is called.

    You can hook it like this:

    
    
                                     
                  
提交回复
热议问题