node.js - xterm.js 基本演示不工作
问题描述
因此,我正在尝试创建一个嵌入了终端的网站,并使用 xterm 来执行此操作。到目前为止,我一直在学习 xterm 并试图让基础知识发挥作用,但我一直遇到困难。下面是终端的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mohammad Nadeem</title>
<link rel="stylesheet" href="node_modules/xterm/dist/xterm.css" />
<script src="node_modules/xterm/dist/xterm.js"></script>
</head>
<body>
<div id = "terminal">
</div>
<script type = "text/javascript">
import { Terminal } from 'xterm';
var term = new Terminal();
term.open(document.getElementById('terminal'), true);
term.fit();
term.writeln('Hello World!');
</script>
</html>
解决方案
import
通过脚本标签添加库时,您不需要使用(ES6 模块)。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mohammad Nadeem</title>
<link rel="stylesheet" href="node_modules/xterm/dist/xterm.css" />
<script src="node_modules/xterm/dist/xterm.js"></script>
</head>
<body>
<div id = "terminal"></div>
<script type = "text/javascript">
var term = new Terminal();
term.open(document.getElementById('terminal'));
term.writeln('Hello World!');
</script>
</body>
</html>
如果你想使用插件 like fit
,你必须导入它,例如:
<script src="node_modules/xterm/lib/addons/fit/fit.js"></script>
推荐阅读
- php - Cookies 功能不保存数据
- scala - Travis CI Scala Play 应用程序构建和部署优化
- react-native - React-native - 如何创建一个可滚动的 flatList,其中所选项目位于中间?
- signal-processing - System.Web.HttpContext.Current.get 返回 null - 网站项目 [SignalR]
- swift - Swift propertyWrapper 无法将声明类型的值转换为指定类型的值
- f# - 在 F# 中计算列表中不变的元素数量
- html - 在同一行上使用 2 个 div 内联块调整窗口大小会触发奇怪的行为
- php - jQuery Popup 不适用于 PHP 的输出
- selenium - Microsoft Edge WebDriver - 无法为自动化使用默认应用数据配置文件 - Edge Ver 80
- python - 如何将字典的值写入 CSV 文件