首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在VueJS中使用ThreeJS

如何在VueJS中使用ThreeJS
EN

Stack Overflow用户
提问于 2019-03-18 22:20:46
回答 1查看 3.8K关注 0票数 0

我想使用threeJS,所以我用npm threeJS安装它--save。我遵循了threeJS文档中的基本教程,但我得到了一个错误。

代码语言:javascript
复制
  mounted () {
    this.initThree();
  },
  methods: {
    initThree() {
      this.scene = new THREE.Scene();
      this.camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

      this.renderer = new THREE.WebGLRenderer( { canvas: document.getElementById( "background" ), alpha: true, antialias: true } );
      this.renderer.setSize( window.innerWidth, window.innerHeight );

      let geometry = new THREE.BoxGeometry( 1, 1, 1 );
      let material = new THREE.MeshBasicMaterial( { color: 0x0000ff } );
      this.cube = new THREE.Mesh( geometry, material );
      this.scene.add( this.cube );

      this.camera.position.z = 5;
      this.animate()

    },

    animate() {

      this.cube.rotation.x += 0.01;
      this.renderer.render( this.scene, this.camera );
      requestAnimationFrame( this.animate() );

    }
  }
}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-18 22:54:44

您的问题与VueJS /ThreeJs无关,您只需解决这一行:

代码语言:javascript
复制
requestAnimationFrame( this.animate() );

它应该是:

代码语言:javascript
复制
requestAnimationFrame(this.animate)

请阅读有关回调的更多信息:https://developer.mozilla.org/en-US/docs/Glossary/Callback_function

编辑:您可以尝试TroisJS,easy ThreeJS与VueJS的集成:https://github.com/troisjs/trois

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55223524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档