article-detail.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. articleInfo: {},
  16. imageList: [],
  17. }
  18. },
  19. computed: {
  20. html() {
  21. const html = this.articleInfo.articleContent
  22. if (html) {
  23. return html.replace(/href=/gi, '')
  24. }
  25. return ''
  26. },
  27. },
  28. mounted() {
  29. this.initData()
  30. },
  31. methods: {
  32. initData() {
  33. const articleInfo = localStorage.getItem('articleInfo')
  34. if (articleInfo) {
  35. this.articleInfo = JSON.parse(articleInfo)
  36. this.fetchArticleDetail()
  37. }
  38. },
  39. async fetchArticleDetail() {
  40. try {
  41. const res = await this.$http.api.getArticleDetail({
  42. articleId: this.articleInfo.articleId,
  43. })
  44. this.articleInfo = { ...this.articleInfo, ...res.data }
  45. } catch (error) {
  46. console.log(error)
  47. }
  48. },
  49. },
  50. }
  51. </script>
  52. <style scoped lang="scss">
  53. /* scss中可以用mixin来扩展 */
  54. @mixin ellipsis($line: 1) {
  55. overflow: hidden;
  56. text-overflow: ellipsis;
  57. display: -webkit-box;
  58. -webkit-line-clamp: $line;
  59. -webkit-box-orient: vertical;
  60. }
  61. // pc 端
  62. @media screen and (min-width: 768px) {
  63. .page {
  64. width: 1200px;
  65. margin: 24px auto;
  66. box-sizing: border-box;
  67. background: #fff;
  68. padding: 24px;
  69. }
  70. .page-top {
  71. padding-bottom: 24px;
  72. border-bottom: 1px solid #d8d8d8;
  73. .title {
  74. @include ellipsis(2);
  75. font-size: 28px;
  76. color: #101010;
  77. line-height: 1.6;
  78. text-align: justify;
  79. }
  80. .date {
  81. font-size: 18px;
  82. color: #b2b2b2;
  83. margin-top: 24px;
  84. }
  85. }
  86. .page-content {
  87. padding-top: 24px;
  88. color: #404040;
  89. }
  90. }
  91. // 移动 端
  92. @media screen and (max-width: 768px) {
  93. }
  94. </style>