You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

59 regels
1.1 KiB

  1. <template>
  2. <view class="page">
  3. <view class="content-body" v-if="loaded">
  4. <mp-html :content="content" />
  5. </view>
  6. <view v-else class="loading">
  7. <u-loading-icon />
  8. </view>
  9. </view>
  10. </template>
  11. <script setup>
  12. import { ref } from 'vue'
  13. import { onLoad } from '@dcloudio/uni-app'
  14. import { get } from '@/utils/request.js'
  15. import mpHtml from '@/uni_modules/mp-html/components/mp-html/mp-html.vue'
  16. const content = ref('')
  17. const loaded = ref(false)
  18. onLoad((options) => {
  19. const key = (options && options.key) || ''
  20. if (key) {
  21. loadContent(key)
  22. }
  23. })
  24. const loadContent = async (key) => {
  25. try {
  26. const res = await get('/api/content', { key })
  27. if (res.data) {
  28. content.value = res.data.content || ''
  29. uni.setNavigationBarTitle({ title: res.data.title || '' })
  30. }
  31. } catch (e) {
  32. console.error('获取内容失败', e)
  33. } finally {
  34. loaded.value = true
  35. }
  36. }
  37. </script>
  38. <style lang="scss" scoped>
  39. .page {
  40. min-height: 100vh;
  41. background: #fff;
  42. }
  43. .content-body {
  44. padding: 32rpx;
  45. }
  46. .loading {
  47. display: flex;
  48. justify-content: center;
  49. padding: 100rpx 0;
  50. }
  51. </style>