xterm.js基本演示不起作用

时间:2018-08-09 01:21:32

标签: node.js xtermjs

因此,我正在尝试创建一个嵌入了终端的网站,并使用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>

1 个答案:

答案 0 :(得分:0)

通过脚本标记添加库时,无需使用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>

如果要使用fit之类的插件,则必须将其导入,例如:

<script src="node_modules/xterm/lib/addons/fit/fit.js"></script>