如何检测场景何时加载到 A-Frame 中?

How to detect when a scene is loaded in A-Frame?

A-Frame加载满后有没有触发事件?现在我已经设法让我的 document.querySelector(".a-enter-vr-button") 工作了,但只是在将它放在 setTimeout 函数中之后,这似乎是一个权宜之计。因此,如果有人有任何方法可以在 A-Frame 完全加载后触发 js 脚本,请告诉我!

您可以使用 loaded 事件:

document.querySelector('a-scene').addEventListener('loaded', function () {...})

但我们建议使用组件,这样您就不必处理等待事件来设置事物:

https://aframe.io/docs/0.4.0/guides/using-javascript-and-dom-apis.html#where-to-place-javascript-code-for-a-frame

AFRAME.registerComponent('log', {
  schema: {type: 'string'},
  init: function () {
    var stringToLog = this.data;
    console.log(stringToLog);
  }
});

然后使用来自 HTML 的组件:

<a-scene log="Hello, Scene!">
  <a-box log="Hello, Box!"></a-box>
</a-scene>