0👍
✅
There are really two ways to handle it. One is to move the script to the bottom of the page, and the second is to use an event to trigger your code when the page is loaded.
The way you typically listen for the page to be loaded these days (without jQuery) is to listen for the DOMContentLoaded event.
document.addEventListener("DOMContentLoaded", function() {
var app = new Vue(...)
});
The primary difference between the DOMContentLoaded
and the load
event being that DOMContentLoaded
fires when all the DOM content has been parsed, and the load
event waits for everything to be loaded including images, and stylesheets, and other things.
Source:stackexchange.com