繁体   English   中英

我该如何调用组件内部的方法,该方法是从react.js中的第3方库更新的?

[英]How do I call a method inside component did update from a 3rd party library in react.js?

好的,我试图从另一个名为xtk库的库中调用一个方法,我已经对JavaScript代码进行了测试,并且效果很好。 现在我只是试图创建一个组件反应将运行它。 我是一个新手,涉及到js和响应,所以我什至在这里可能都不问正确的问题。

componentDidMount = function(){
  this.v = X.renderer3D(this.refs.v);
  this.v.container ='v';
  this.v.init();
  this.randF = X.mesh.randF(this.refs.randf);
  this.file.randF = '../Assets/rgrid.vtk';
  this.v.add(this.randF);
  this.v.render();
}

我本质上是试图用那个react.js代码执行这个javascript代码。

window.onload = function() {

  // create and initialize a 3D renderer
  var r = new X.renderer3D();
  r.init();

  // create a new X.mesh
  var skull = new X.mesh();
  // .. and associate the .vtk file to it
  skull.file = 'http://x.babymri.org/?skull.vtk';
  // .. make it transparent
  skull.opacity = 0.7;

  // .. add the mesh
  r.add(skull);

  // re-position the camera to face the skull
  r.camera.position = [0, 400, 0];



  r.render();

};

我一直不断地向我抛出错误,说render3D不是类,X不是构造函数,依此类推。 从本质上讲,我已经花了几天的时间来尝试主要靠我自己解决这个问题,因此,即使有任何建议,无论从哪方面来看,它都绝对是很棒的。

谢谢。

好的,这花了我很长时间才弄清楚,所以我希望其他人不要经历这个。

您不能简单地安装xtk,必须从create-react-app弹出,删除config.lock文件和所有模块,然后在其上运行npm install并在其上运行xtk安装。

这样您就可以使用它了。

通常,这只是使用完整的强大的第三方库而无需从头开始构建所有内容的方法。

暂无
暂无

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

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