toc-item.vue 888 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <li class="item">
  3. <a
  4. class="toc__link"
  5. :class="{ 'active': active === item.id }"
  6. :href="'#' + encodeURIComponent(item.heading)"
  7. v-text="item.heading">
  8. </a>
  9. <ol
  10. class="group"
  11. v-if="item.children"
  12. v-show="active >= item.id && active <= (item.id + item.children.length || 0)">
  13. <el-toc-item
  14. :item="sub"
  15. class="item"
  16. :active="active"
  17. v-for="sub in item.children">
  18. </el-toc-item>
  19. </ol>
  20. </li>
  21. </template>
  22. <script>
  23. /**
  24. * 浮动在右边的目录子项
  25. */
  26. export default {
  27. name: 'el-toc-item',
  28. props: {
  29. item: Object,
  30. active: Number
  31. },
  32. methods: {
  33. encodeURIComponent(source) {
  34. return encodeURIComponent(source);
  35. }
  36. }
  37. };
  38. </script>
  39. <style lang="css">
  40. a {
  41. color: inherit;
  42. text-decoration: none;
  43. }
  44. </style>