2

我不确定我在这里搞砸了什么。我已经设法在基本的 A-Frame 中编写了自己的组件,但是自从转向 aframe-react 后,我​​遇到了错误:

Error in ./src/components.js

C:\PATH_TO\src\components.js
  1:1  error  'AFRAME' is not defined  no-undef

组件.js:

AFRAME.registerComponent('pointer_click', {
    // ...
});

我是不是导入错了?

import 'aframe';
import 'aframe-animation-component';
import 'aframe-particle-system-component';
import 'babel-polyfill';
import {Entity, Scene} from 'aframe-react';
import React from 'react';
import ReactDOM from 'react-dom';
import './components.js';
4

2 回答 2

2

如果您使用的是 create-react-app,那么您需要按照这个create-react-app-global-vars来引用“AFRAME”作为全局变量。

基本上,将它包含在 AFrame 组件文件的顶部。

const AFRAME = window.AFRAME;
于 2018-01-13T14:24:33.053 回答
0

也许这只是一个 lint 错误或 bundler 错误?你用的是什么捆绑器?我想知道您是否必须在AFRAME某处(例如,/* globals AFRAME */在顶部)声明为全局或AFRAME在某些配置中定义为全局。

如果您可能正在使用semistandardlinter,则可以放入 package.json:

"semistandard": {
  "globals": [
    "AFRAME",
    "THREE"
  ],
  "ignore": [
    "build/**"
  ]
}
于 2017-09-18T22:31:53.850 回答