【发布时间】:2020-08-26 04:11:45
【问题描述】:
我想在我的 React 应用程序中使用 guacamole-common-js,并且已经通过 guacamole-lite 在 docker 和 guacamole 客户端中设置了 guaca。我已经成功地看到了纯 HTML 和 javascript 的视图。但是,我无法在 React JSX 中渲染它。 这是我的代码:
import Guacamole from "guacamole-common-js";
let guaca = new Guacamole.Client(new Guacamole.WebSocketTunnel(webSocketFullUrl));
guaca.onerror = function (error) {
alert(error);
};
guaca.connect();
// Disconnect on close
window.onunload = function () {
guaca.disconnect();
}
let display = document.getElementById("display");
display.appendChild(guaca.getDisplay().getElement());
然后渲染它:
React.createElement("div", {id, "display"})
我也尝试使用 Ref 像 follow 但仍然无法正常工作:
constructor(props) {
super(props);
this.displayRef = React.createRef();
this.guacaRef = React.createRef();
}
this.guacaRef.current = new Guacamole.Client(new Guacamole.WebSocketTunnel(webSocketFullUrl));
this.guacaRef.current.onerror = function (error) {
alert(error);
};
this.guacaRef.current.connect();
// Disconnect on close
window.onunload = function () {
this.guacaRef.current.disconnect();
}
this.displayRef.current.appendChild(this.guacaRef.current.getDisplay().getElement());
渲染它:
<div ref={displayRef}/>
我是新手,如有任何帮助,我们将不胜感激。
【问题讨论】:
标签: javascript reactjs guacamole