简体   繁体   English

Go-debug-module.js:15 未捕获错误:无效的 DIV id; 无法获取 ID 为:gojs 的元素

[英]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.我使用以下方式为我的项目导入gojs但找不到 div。

https://codesandbox.io/s/magical-snowflake-76x31o?file=/src/App.vue 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.发生这种情况是因为浏览器尚未加载您的 DOM 元素,但脚本已加载,因此脚本在元素可用之前执行。

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;您似乎试图通过使用init()来解决此问题,但它也会立即运行,而是向 window.onload 事件添加一个事件侦听器: window.onload += init;

Or preferably on DOMContentLoaded as it's executed before external sources has been loaded, unlike window.onload.或者最好在 DOMContentLoaded 上执行,因为它在加载外部源之前执行,这与 window.onload 不同。

document.addEventListener("DOMContentLoaded", init);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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