EditionToc.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <MainContentLayout id="edition-toc">
  3. <template v-if="!content" #header>
  4. <span>Loading ...</span>
  5. </template>
  6. <template v-if="meta" #header>
  7. <h1>{{ meta.author }}</h1>
  8. </template>
  9. <!-- default slot -->
  10. <EdText v-if="textdata" :textdata="textdata" />
  11. <template #nav>
  12. <EdToc :content="content" />
  13. </template>
  14. </MainContentLayout>
  15. </template>
  16. <script>
  17. import { REST } from 'api/rest-axios'
  18. import MainContentLayout from '../components/Layouts/MainContentLayout'
  19. import EdText from '../components/Content/EdText'
  20. import EdToc from '../components/Content/EdToc'
  21. export default {
  22. name: 'EditionToc',
  23. components: {
  24. MainContentLayout,
  25. EdText,
  26. EdToc
  27. },
  28. data: () => ({
  29. content: null,
  30. meta: null,
  31. editionid: null,
  32. textid: null,
  33. textdata: null
  34. }),
  35. watch: {
  36. textid: function (newid, oldid) {
  37. // console.log('textid watcher', this, newid, oldid)
  38. this.getTextContent()
  39. }
  40. },
  41. beforeCreate () {
  42. console.log('texts this.$route', this.$route)
  43. // http://localhost:8984/texts/gdpSauval1724/toc
  44. this.editionid = this.$route.params.id
  45. // get the edition's toc
  46. REST.get(`/texts/` + this.$route.params.id + `/toc`, {})
  47. .then(({ data }) => {
  48. console.log('texts/toc REST: data', data)
  49. this.meta = data.meta
  50. if (data.content) {
  51. if (Array.isArray(data.content)) {
  52. this.content = data.content
  53. } else {
  54. this.content = [data.content]
  55. }
  56. }
  57. })
  58. .catch((error) => {
  59. console.warn('Issue with locorum', error)
  60. Promise.reject(error)
  61. })
  62. },
  63. created () {
  64. // get the text if textid available
  65. if (this.$route.params.textid) {
  66. this.textid = this.$route.params.textid
  67. // this.getTextContent()
  68. }
  69. },
  70. beforeRouteUpdate (to, from, next) {
  71. // called when the route that renders this component has changed,
  72. // but this component is reused in the new route.
  73. // For example, for a route with dynamic params `/foo/:id`, when we
  74. // navigate between `/foo/1` and `/foo/2`, the same `Foo` component instance
  75. // will be reused, and this hook will be called when that happens.
  76. // has access to `this` component instance.
  77. // console.log('beforeRouteUpdate to', to)
  78. if (to.params.textid) {
  79. this.textid = to.params.textid
  80. }
  81. next()
  82. },
  83. methods: {
  84. getTextContent () {
  85. console.log('getTextContent', this.textid)
  86. if (this.textid) {
  87. REST.get(`/items/` + this.textid, {})
  88. .then(({ data }) => {
  89. console.log('text REST: data', data)
  90. this.textdata = data
  91. })
  92. .catch((error) => {
  93. console.warn('Issue with getTextContent', error)
  94. Promise.reject(error)
  95. })
  96. }
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. </style>