XtermVue.vue 924 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <div class="xterm" />
  3. </template>
  4. <script>
  5. import 'xterm/css/xterm.css'
  6. import { Terminal } from 'xterm'
  7. import { FitAddon } from 'xterm-addon-fit'
  8. import { WebLinksAddon } from 'xterm-addon-web-links'
  9. export default {
  10. mounted() {
  11. this.$term = new Terminal({})
  12. this.$fitAddon = new FitAddon()
  13. this.$term.loadAddon(this.$fitAddon)
  14. this.$term.loadAddon(new WebLinksAddon())
  15. this.$term.open(this.$el)
  16. this.$fitAddon.fit()
  17. this.$term.onTitleChange((title) => this.$emit('title-change', title))
  18. },
  19. methods: {
  20. fit() {
  21. this.$fitAddon.fit()
  22. },
  23. focus() {
  24. this.$term.focus()
  25. },
  26. blur() {
  27. this.$term.blur()
  28. },
  29. paste(data){
  30. this.$term.paste(data)
  31. }
  32. }
  33. }
  34. </script>
  35. <style scoped>
  36. .xterm {
  37. height: 100%;
  38. width: 100%;
  39. }
  40. </style>