To make Vue aware of when a page has loaded, you can use either window.addEventListener(‘DOMContentLoaded’) or window.onload. Here’s how to implement it:
-
Using DOMContentLoaded:
if (typeof window !== ‘undefined’) { window.addEventListener(‘DOMContentLoaded’, () => { // Page is ready; initialize Vue here new Vue({ // your options }); }); } -
Using window.onload:
if (typeof window !== ‘undefined’) { window.onload = function() { // Page is fully loaded; initialize Vue here new Vue({ // your options }); }; }
Option 1 is preferable as it fires earlier, making the page ready sooner.
Leave a Reply
You must be logged in to post a comment.