detail.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view v-if="!isLoading" class="container b-f p-b">
  3. <view class="article-title">
  4. <text class="f-32">{{ detail.title }}</text>
  5. </view>
  6. <view class="article-little dis-flex flex-x-between m-top10">
  7. <view class="article-little__left">
  8. <text class="article-views f-24 col-8">{{ detail.show_views }}次浏览</text>
  9. </view>
  10. <view class="article-little__right">
  11. <text class="article-views f-24 col-8">{{ detail.view_time }}</text>
  12. </view>
  13. </view>
  14. <view class="article-content m-top20">
  15. <mp-html :content="detail.content" />
  16. </view>
  17. <!-- 快捷导航 -->
  18. <shortcut />
  19. </view>
  20. </template>
  21. <script>
  22. import Shortcut from '@/components/shortcut'
  23. import * as ArticleApi from '@/api/article'
  24. export default {
  25. components: {
  26. Shortcut
  27. },
  28. data() {
  29. return {
  30. // 当前文章ID
  31. articleId: null,
  32. // 加载中
  33. isLoading: true,
  34. // 当前文章详情
  35. detail: null
  36. }
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad(options) {
  42. // 记录文章ID
  43. this.articleId = options.articleId
  44. // 获取文章详情
  45. this.getArticleDetail()
  46. },
  47. methods: {
  48. // 获取文章详情
  49. getArticleDetail() {
  50. const app = this
  51. app.isLoading = true
  52. ArticleApi.detail(app.articleId)
  53. .then(result => {
  54. app.detail = result.data.detail
  55. })
  56. .finally(() => app.isLoading = false)
  57. }
  58. },
  59. /**
  60. * 分享当前页面
  61. */
  62. onShareAppMessage() {
  63. const app = this
  64. // 构建页面参数
  65. const params = app.$getShareUrlParams({ articleId: app.articleId });
  66. return {
  67. title: app.detail.title,
  68. path: "/pages/article/detail?" + params
  69. }
  70. },
  71. /**
  72. * 分享到朋友圈
  73. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  74. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  75. */
  76. onShareTimeline() {
  77. const app = this
  78. // 构建页面参数
  79. const params = app.$getShareUrlParams({ articleId: app.articleId });
  80. return {
  81. title: app.detail.title,
  82. path: "/pages/article/detail?" + params
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .container {
  89. min-height: 100vh;
  90. padding: 20rpx;
  91. background: #fff;
  92. }
  93. .article-content {
  94. font-size: 28rpx;
  95. }
  96. </style>