article-detail.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="page">
  3. <div class="page-top">
  4. <div class="title" v-text="articleInfo.articleTitle"></div>
  5. <div class="date">{{ articleInfo.createTime | dateFormat }}</div>
  6. </div>
  7. <div class="page-content" v-html="html"></div>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. layout: 'app',
  13. data() {
  14. return {
  15. articleId: '',
  16. articleInfo: {},
  17. imageList: [],
  18. }
  19. },
  20. computed: {
  21. html() {
  22. const html = this.articleInfo.articleContent
  23. if (html) {
  24. return html.replace(/href=/gi, '')
  25. }
  26. return ''
  27. },
  28. },
  29. mounted() {
  30. this.initData()
  31. },
  32. methods: {
  33. initData() {
  34. this.articleId = parseInt(this.$route.query.id)
  35. this.fetchArticleDetail()
  36. },
  37. async fetchArticleDetail() {
  38. try {
  39. const res = await this.$http.api.getArticleDetail({
  40. articleId: this.articleId,
  41. })
  42. this.articleInfo = res.data
  43. } catch (error) {
  44. console.log(error)
  45. }
  46. },
  47. },
  48. }
  49. </script>
  50. <style scoped lang="scss">
  51. /* scss中可以用mixin来扩展 */
  52. @mixin ellipsis($line: 1) {
  53. overflow: hidden;
  54. text-overflow: ellipsis;
  55. display: -webkit-box;
  56. -webkit-line-clamp: $line;
  57. -webkit-box-orient: vertical;
  58. }
  59. // pc 端
  60. @media screen and (min-width: 768px) {
  61. .page {
  62. width: 1200px;
  63. margin: 24px auto;
  64. box-sizing: border-box;
  65. background: #fff;
  66. padding: 24px;
  67. }
  68. .page-top {
  69. padding-bottom: 24px;
  70. border-bottom: 1px solid #d8d8d8;
  71. .title {
  72. font-size: 28px;
  73. color: #101010;
  74. line-height: 1.6;
  75. text-align: justify;
  76. }
  77. .date {
  78. font-size: 18px;
  79. color: #b2b2b2;
  80. margin-top: 24px;
  81. }
  82. }
  83. .page-content {
  84. padding-top: 24px;
  85. color: #404040;
  86. }
  87. }
  88. // 移动 端
  89. @media screen and (max-width: 768px) {
  90. .page {
  91. box-sizing: border-box;
  92. background: #fff;
  93. padding: 4vw;
  94. }
  95. .page-top {
  96. .title {
  97. font-size: 4.2vw;
  98. color: #101010;
  99. line-height: 1.6;
  100. text-align: justify;
  101. }
  102. .date {
  103. font-size: 3.2vw;
  104. color: #b2b2b2;
  105. margin-top: 4vw;
  106. }
  107. }
  108. .page-content {
  109. padding-top: 24px;
  110. color: #404040;
  111. }
  112. }
  113. </style>