TocItem.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <section
  3. :uuid="item.uuid"
  4. :level="level"
  5. >
  6. <component
  7. :is="titlelevel"
  8. v-if="title"
  9. class="toc-title"
  10. :uuid="item.uuid"
  11. >
  12. <a
  13. :href="'/edition/'+editionid+'/'+item.uuid"
  14. :uuid="item.uuid"
  15. @click.prevent="onclick"
  16. @keyup.enter="onclick"
  17. >
  18. {{ title }}
  19. </a>
  20. </component>
  21. <ul v-if="children.length">
  22. <li v-for="child in children" :key="child.uuid">
  23. <TocItem :item="child" :level="nextLevel" :editionid="editionid" />
  24. </li>
  25. </ul>
  26. </section>
  27. </template>
  28. <script>
  29. import TocItem from './TocItem'
  30. export default {
  31. name: 'TocItem',
  32. components: {
  33. TocItem
  34. },
  35. props: {
  36. item: Object,
  37. level: Number,
  38. editionid: String
  39. },
  40. // data: () => ({
  41. //
  42. // })
  43. computed: {
  44. children () {
  45. // check if children exists and if it is an array
  46. // this shoudn't be necessary
  47. return this.item.children ? Array.isArray(this.item.children) ? this.item.children : [this.item.children] : []
  48. },
  49. title () {
  50. // this shoudn't be necessary
  51. if (this.item.title && Array.isArray(this.item.title)) {
  52. return this.item.title.join(' ')
  53. } else {
  54. return this.item.title
  55. }
  56. },
  57. titlelevel () {
  58. return 'h' + this.level
  59. },
  60. nextLevel () {
  61. return this.level + 1
  62. }
  63. },
  64. // beforeCreate () {
  65. // console.log('editionid', this.editionid)
  66. // },
  67. methods: {
  68. onclick (e) {
  69. console.log('clicked on toc text', this.editionid, e)
  70. this.$router.push({
  71. name: `editiontoctext`,
  72. params: {
  73. id: this.editionid,
  74. textid: e.target.getAttribute('uuid')
  75. }
  76. })
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. </style>