我想使用threeJS,所以我用npm threeJS安装它--save。我遵循了threeJS文档中的基本教程,但我得到了一个错误。
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() );
}
}
}

发布于 2019-03-18 22:54:44
您的问题与VueJS /ThreeJs无关,您只需解决这一行:
requestAnimationFrame( this.animate() );它应该是:
requestAnimationFrame(this.animate)请阅读有关回调的更多信息:https://developer.mozilla.org/en-US/docs/Glossary/Callback_function
编辑:您可以尝试TroisJS,easy ThreeJS与VueJS的集成:https://github.com/troisjs/trois
https://stackoverflow.com/questions/55223524
复制相似问题