Document.vue 855 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template lang="pug">
  2. vue-markdown(:source="data")
  3. </template>
  4. <script>
  5. import VueMarkdown from "@/components/VueMarkdown"
  6. export default {
  7. name: "Document",
  8. components: {VueMarkdown},
  9. data() {
  10. return {
  11. data: ''
  12. }
  13. },
  14. created() {
  15. // This ensures to not update twice after editing
  16. setTimeout(() => {
  17. this.$ws.addCMDListener(6, this.getFile)
  18. }, 1000)
  19. },
  20. beforeDestroy() {
  21. this.$ws.removeCMDListener(6, this.getFile)
  22. },
  23. methods: {
  24. getFile(update) {
  25. if(update !== this.filename) return
  26. fetch("/_doc/" + this.filename)
  27. .then(response => response.text())
  28. .then(text => this.data = text)
  29. }
  30. },
  31. computed: {
  32. filename() {
  33. return this.$route.params.pathMatch
  34. }
  35. },
  36. mounted() {
  37. this.getFile(this.filename)
  38. }
  39. }
  40. </script>
  41. <style scoped>
  42. </style>