index.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="news" :style="{ 'height': setHeight + 'px' }">
  3. <view class="title">{{news.title}}</view>
  4. <view class="time">{{news.time | formatDate}}</view>
  5. <rich-text :nodes="news.content"></rich-text>
  6. </view>
  7. </template>
  8. <script>
  9. import {
  10. newsDetail
  11. } from '@/api/api.js';
  12. export default {
  13. data() {
  14. return {
  15. id: 0,
  16. news: {},
  17. setHeight: 0
  18. }
  19. },
  20. //时间戳的处理
  21. filters: {
  22. formatDate: function(value) {
  23. var date = new Date();
  24. var month = date.getMonth() + 1;
  25. var hours = date.getHours();
  26. if (hours < 10)
  27. hours = "0" + hours;
  28. var minutes = date.getMinutes();
  29. if (minutes < 10)
  30. minutes = "0" + minutes;
  31. var time = date.getFullYear() + "-" + month + "-" + date.getDate() +
  32. " " + hours + ":" + minutes;
  33. return time;
  34. }
  35. },
  36. mounted() {
  37. let that = this
  38. uni.getSystemInfo({
  39. success: function (res) {
  40. that.setHeight = res.windowHeight
  41. }
  42. })
  43. },
  44. onLoad(options) {
  45. this.id = options.id;
  46. this.getNewsDetail();
  47. },
  48. methods: {
  49. getNewsDetail: function() {
  50. let that = this;
  51. newsDetail({id:that.id}).then(res => {
  52. that.news = res.data;
  53. })
  54. }
  55. }
  56. }
  57. </script>
  58. <style scoped lang="scss">
  59. .news{
  60. background: #fff;
  61. padding: 30rpx;
  62. color:#333;
  63. }
  64. .title{
  65. font-size: 32rpx;
  66. margin-bottom: 10rpx;
  67. font-weight: bolder;
  68. }
  69. .time{
  70. color:#999;
  71. margin-bottom: 20rpx;
  72. }
  73. </style>