当前位置:   article > 正文

小程序展示markdown文件 参考_小程序 markdown

小程序 markdown

uni-app——在微信小程序中实现markdown文章解析展示 - 简书

1、发请求拿到数据库的内容

  1. onLoad() {
  2. console.log('资料页面');
  3. uni.request({
  4. url: httpUrl + '/getNotice',
  5. method: 'GET',
  6. header: {
  7. "Content-Type": "application/json"
  8. },
  9. }).then((res) => {
  10. res[1].data.filter((item, index) => {
  11. item.n_time = newDate(item.n_time)
  12. item.d_title = item.n_title
  13. item.n_title = truncate(item.n_title, 15)
  14. })
  15. res[1].data.sort((a, b) => {
  16. return new Date(b.n_time).getTime() - new Date(a.n_time).getTime()
  17. })
  18. this.$store.state.noticeNoChangeData = res[1].data
  19. this.$store.state.noticeData = res[1].data
  20. this.$store.state.totalNum = res[1].data.length
  21. this.$store.commit('getPageData')
  22. this.$store.commit('changePageArr')
  23. }).catch(err => {
  24. console.log(err)
  25. })
  26. this.changePagesize()
  27. },

 2、把数据传到子页面 注意这里markdown里面存在base64和特殊字符 转换的时候要注意

 

 最后就是小程序端的展示了

这里参考了 uni-app——在微信小程序中实现markdown文章解析展示 - 简书

  • 下载  mp-html

 

  1. <template>
  2. <view class="newsDetails_app">
  3. <mp-html :content="html" />
  4. </view>
  5. </template>
  6. <script>
  7. import showdown from 'showdown';
  8. import mpHtml from "mp-html/dist/uni-app/components/mp-html/mp-html";
  9. export default {
  10. data() {
  11. return {
  12. itemData: [],
  13. markdown: '',
  14. html: "<div>Hello World!</div>",
  15. }
  16. },
  17. components: {
  18. mpHtml,
  19. },
  20. methods: {
  21. },
  22. onLoad(options) {
  23. console.log('详情页数据');
  24. try {
  25. this.itemData = JSON.parse(decodeURIComponent(options.itemData))
  26. console.log(this.itemData);
  27. this.markdown = this.itemData.n_markdown
  28. let converter = new showdown.Converter()
  29. this.html = converter.makeHtml(this.markdown)
  30. // console.log(html);
  31. } catch (err) {
  32. console.error(err)
  33. }
  34. },
  35. }
  36. </script>
  37. <style>
  38. .newsDetails_app {
  39. width: calc(100% - 40rpx);
  40. height: calc(100% - 40rpx);
  41. position: absolute;
  42. /* background-color: pink; */
  43. padding: 0 20rpx;
  44. padding-bottom: 20rpx;
  45. overflow: scroll;
  46. }
  47. .newsDetails_app::-webkit-scrollbar {
  48. width: 0;
  49. height: 0;
  50. }
  51. .newsDetails_title {
  52. color: #333;
  53. font-size: 32rpx;
  54. font-weight: bold;
  55. height: 80rpx;
  56. line-height: 80rpx;
  57. /* background-color: skyblue; */
  58. }
  59. .newsDetails_time {
  60. font-size: 24rpx;
  61. height: 60rpx;
  62. border-bottom: 1rpx solid #CDD4DD;
  63. }
  64. .newServer {
  65. font-size: 32rpx;
  66. font-weight: bold;
  67. color: #777986;
  68. line-height: 50rpx;
  69. margin-top: 50rpx;
  70. }
  71. .newServer_red {
  72. color: red;
  73. }
  74. .warm_title {
  75. font-size: 28rpx;
  76. display: flex;
  77. align-items: center;
  78. color: #FF9900;
  79. margin-bottom: 10rpx;
  80. }
  81. .warm_title>image {
  82. width: 30rpx;
  83. height: 30rpx;
  84. }
  85. .warm_reminder {
  86. margin: 20rpx 0;
  87. }
  88. .warm_content {
  89. font-size: 26rpx;
  90. margin-top: 20rpx;
  91. }
  92. .content_image {
  93. margin: 24rpx 0;
  94. display: flex;
  95. justify-content: center;
  96. }
  97. .content_image>image {
  98. width: 90%;
  99. }
  100. .content_hint {
  101. font-size: 20rpx;
  102. color: red;
  103. }
  104. .activity {
  105. margin: 20rpx 0;
  106. }
  107. .activity_title {
  108. font-size: 28rpx;
  109. font-weight: bold;
  110. color: #337FE6;
  111. margin-bottom: 20rpx;
  112. }
  113. .activity_content {
  114. font-size: 26rpx;
  115. color: #337FE6;
  116. }
  117. .activity_center {
  118. font-size: 26rpx;
  119. }
  120. .center_title {
  121. color: #337FE6;
  122. }
  123. .center_content {
  124. text-indent: 2rem;
  125. }
  126. .center_image {
  127. display: flex;
  128. justify-content: center;
  129. margin: 20rpx 0;
  130. }
  131. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/76963
推荐阅读
  

闽ICP备14008679号