Output.vue 889 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <div class="output">
  3. <pre><code v-html="msg"></code> </pre>
  4. </div>
  5. </template>
  6. <script>
  7. import Vue from "vue"
  8. import editor from "vue2-ace"
  9. import { EventBus } from "../common/eventbus"
  10. export default {
  11. mounted() {
  12. EventBus.$on("log", this.dolog) // place this elsewhere?
  13. },
  14. data: () => {
  15. return {
  16. counter: 0,
  17. msg: ""
  18. }
  19. },
  20. methods: {
  21. dolog (...msg) {
  22. var doscroll = false
  23. var tolerance = 10
  24. var innerHeight = parseInt(getComputedStyle(this.$el).getPropertyValue("height"))
  25. if (this.$el.scrollTop + innerHeight >= this.$el.scrollHeight - tolerance) {
  26. doscroll = true
  27. }
  28. this.msg += "[" + this.counter + "] " + msg.join(" ") + "\n"
  29. this.counter++
  30. if (doscroll) {
  31. Vue.nextTick(() => { // This should be in the next tick
  32. this.$el.scrollTop = this.$el.scrollHeight
  33. })
  34. }
  35. }
  36. },
  37. components: {editor}
  38. }
  39. </script>