简体   繁体   中英

Go-debug-module.js:15 Uncaught Error: Invalid DIV id; could not get element with id: gojs

I use below way to import gojs for my project but failed to find the div.

https://codesandbox.io/s/magical-snowflake-76x31o?file=/src/App.vue

I get error:

Go-debug-module.js:15 Uncaught Error: Invalid DIV id; could not get element with id: gojs

This happens because your DOM element has not been loaded yet by the browser, but the script has, so the script is executing before the element is available.

It appears that you tried to fix this by using init() but that runs right away as well, instead, add an event listener to the window.onload event: window.onload += init;

Or preferably on DOMContentLoaded as it's executed before external sources has been loaded, unlike window.onload.

document.addEventListener("DOMContentLoaded", init);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM