XtermVue.vue 859 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <div class="xterm" />
  3. </template>
  4. <script>
  5. import 'xterm/dist/xterm.css'
  6. import { Terminal } from 'xterm'
  7. import * as fit from 'xterm/lib/addons/fit/fit'
  8. Terminal.applyAddon(fit)
  9. export default {
  10. mounted() {
  11. this.$term = new Terminal({})
  12. this.$term.open(this.$el)
  13. this.$term.fit()
  14. this.$term.on('blur', () => this.$emit('blur'))
  15. this.$term.on('focus', () => this.$emit('focus'))
  16. this.$term.on('title', title => this.$emit('title-change', title))
  17. },
  18. beforeDestroy () {
  19. this.$term.destroy()
  20. },
  21. methods: {
  22. fit() {
  23. this.$term.fit()
  24. },
  25. focus() {
  26. this.$term.focus()
  27. },
  28. blur() {
  29. this.$term.blur()
  30. },
  31. paste(data){
  32. this.$term.paste(data)
  33. }
  34. }
  35. }
  36. </script>