0

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

1 回答 1

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>

如果你想使用插件 like fit,你必须导入它,例如:

<script src="node_modules/xterm/lib/addons/fit/fit.js"></script>
于 2018-08-20T09:40:29.320 回答