richtext.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!-- 文章展示 -->
  2. <template>
  3. <s-layout :bgStyle="{ color: '#FFF' }" :title="state.title" class="set-wrap">
  4. <view class="ss-p-30 richtext"><mp-html :content="state.content"></mp-html></view>
  5. </s-layout>
  6. </template>
  7. <script setup>
  8. import { onLoad } from '@dcloudio/uni-app';
  9. import { reactive } from 'vue';
  10. import ArticleApi from '@/sheep/api/promotion/article';
  11. const state = reactive({
  12. title: '',
  13. content: '',
  14. });
  15. async function getRichTextContent(id, title) {
  16. const { code, data } = await ArticleApi.getArticle(id, title);
  17. if (code !== 0) {
  18. return;
  19. }
  20. state.content = data.content;
  21. // 标题不一致时,修改标题
  22. if (state.title !== data.title) {
  23. state.title = data.title;
  24. uni.setNavigationBarTitle({
  25. title: state.title,
  26. });
  27. }
  28. }
  29. onLoad((options) => {
  30. if (options.title) {
  31. state.title = options.title;
  32. uni.setNavigationBarTitle({
  33. title: state.title,
  34. });
  35. }
  36. getRichTextContent(options.id, options.title);
  37. });
  38. </script>
  39. <style lang="scss" scoped>
  40. .set-title {
  41. margin: 0 30rpx;
  42. }
  43. :deep() {
  44. image {
  45. display: block;
  46. }
  47. }
  48. </style>