index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="article-detail page-content">
  3. <div class="content">
  4. <h1>{{ articleTitle }}</h1>
  5. <div class="markdown-body" v-highlight v-html="articleHtml"></div>
  6. </div>
  7. <ArtBackToTop />
  8. </div>
  9. </template>
  10. <script setup lang="ts">
  11. import '@/assets/styles/markdown.scss'
  12. import '@/assets/styles/one-dark-pro.scss'
  13. import { useCommon } from '@/composables/useCommon'
  14. import axios from 'axios'
  15. // import 'highlight.js/styles/atom-one-dark.css';
  16. // import 'highlight.js/styles/vs2015.css';
  17. defineOptions({ name: 'ArticleDetail' })
  18. const articleId = ref(0)
  19. const router = useRoute()
  20. const articleTitle = ref('')
  21. const articleHtml = ref('')
  22. onMounted(() => {
  23. useCommon().scrollToTop()
  24. articleId.value = Number(router.query.id)
  25. getArticleDetail()
  26. })
  27. const getArticleDetail = async () => {
  28. if (articleId.value) {
  29. const res = await axios.get('https://www.qiniu.lingchen.kim/blog_detail.json')
  30. if (res.data.code === 200) {
  31. articleTitle.value = res.data.data.title
  32. articleHtml.value = res.data.data.html_content
  33. }
  34. }
  35. }
  36. </script>
  37. <style lang="scss">
  38. .article-detail {
  39. .content {
  40. max-width: 800px;
  41. margin: auto;
  42. margin-top: 60px;
  43. .markdown-body {
  44. margin-top: 60px;
  45. img {
  46. width: 100%;
  47. border: 1px solid var(--art-gray-200);
  48. }
  49. pre {
  50. position: relative;
  51. &:hover {
  52. .copy-button {
  53. opacity: 1;
  54. }
  55. }
  56. &::before {
  57. position: absolute;
  58. top: 0;
  59. left: 50px;
  60. width: 1px;
  61. height: 100%;
  62. content: '';
  63. background: #0a0a0e;
  64. }
  65. }
  66. .code-wrapper {
  67. overflow-x: auto;
  68. }
  69. .line-number {
  70. position: sticky;
  71. left: 0;
  72. z-index: 2;
  73. box-sizing: border-box;
  74. display: inline-block;
  75. width: 50px;
  76. margin-right: 10px;
  77. font-size: 14px;
  78. color: #9e9e9e;
  79. text-align: center;
  80. }
  81. .copy-button {
  82. position: absolute;
  83. top: 6px;
  84. right: 6px;
  85. z-index: 1;
  86. width: 40px;
  87. height: 40px;
  88. font-size: 20px;
  89. line-height: 40px;
  90. color: #999;
  91. text-align: center;
  92. cursor: pointer;
  93. background-color: #000;
  94. border: none;
  95. border-radius: 8px;
  96. opacity: 0;
  97. transition: all 0.2s;
  98. }
  99. }
  100. }
  101. }
  102. </style>