article-detail.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. @include ellipsis(2);
  73. font-size: 28px;
  74. color: #101010;
  75. line-height: 1.6;
  76. text-align: justify;
  77. }
  78. .date {
  79. font-size: 18px;
  80. color: #b2b2b2;
  81. margin-top: 24px;
  82. }
  83. }
  84. .page-content {
  85. padding-top: 24px;
  86. color: #404040;
  87. }
  88. }
  89. // 移动 端
  90. @media screen and (max-width: 768px) {
  91. }
  92. </style>