How to run VueJS code only after Vue is fully loaded and initialized?

后端 未结 2 1881
盖世英雄少女心
盖世英雄少女心 2021-01-31 16:20

I am working on a Vue component that will be placed on multiple websites via a CMS system. The issue I encounter is that even if my js scripts loading order is correct, sometime

2条回答
  •  长发绾君心
    2021-01-31 17:22

    Use the load event to wait until all resources have finished loading:

    
    

    Further explanation

    DOMContentLoaded is an event fired when the HTML is parsed and rendered and DOM is constructed. It is usually fired pretty fast in the lifetime of the app. On the other hand, load is only fired when all the resources (images, stylesheets etc.) are retrieved from the network and available to the browser.

    You can also use the load event for a specific script.

提交回复
热议问题