[英]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.