detail.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view class="container">
  3. <navBar name="信息详情"></navBar>
  4. <view class="title">{{info.title}}</view>
  5. <view >{{info.overview}}</view>
  6. <image v-if="info.cover" :src="info.cover" class="img" mode="aspectFill" />
  7. <rich-text :nodes="info.content"></rich-text>
  8. </view>
  9. </template>
  10. <script>
  11. const config = require('@/common/config.js');
  12. const http = require('@/common/http.js');
  13. const request = require('@/common/request.js');
  14. const common = require('@/common/common.js');
  15. export default {
  16. data() {
  17. return {
  18. id: '',
  19. info: {}
  20. }
  21. },
  22. onLoad(options) {
  23. this.id = options.id
  24. this.queryMsgDetail()
  25. },
  26. methods: {
  27. queryMsgDetail() {
  28. const req = { type:'PLAT',id : Number(this.id) }
  29. http.postApi(config.API_MESSAGE_DTL, req, res => {
  30. if (res.succeed) {
  31. this.info = res.data.data
  32. // 正则匹配所有<img>标签并插入自适应属性
  33. this.info.content = (this.info.content || '') .replace(/<img/g, '<img style="max-width: 100%; height: auto;"');
  34. }
  35. })
  36. },
  37. }
  38. }
  39. </script>
  40. <style lang="scss" scoped>
  41. .container{
  42. display: flex;
  43. flex-direction: column;
  44. padding: 20rpx;
  45. .title{
  46. font-size: 36rpx;
  47. font-weight: bold;
  48. margin: 20rpx;
  49. }
  50. .img{
  51. width: 750rpx;
  52. }
  53. }
  54. </style>