1. <template>
    2. <view class='news_detail'>
    3. <text class='title'>{{detail.title}}</text>
    4. <view class='info'>
    5. <text>发表时间:{{detail.add_time | formatDate}}</text>
    6. <text>浏览:{{detail.click}}</text>
    7. </view>
    8. <view class='content'>
    9. {{detail.content}}
    10. </view>
    11. </view>
    12. </template>
    13. <script>
    14. export default {
    15. data() {
    16. return {
    17. id:0,
    18. detail:{}
    19. };
    20. },
    21. methods:{
    22. async getNewsDetail(){
    23. const res = await this.$myRequest({
    24. url:'/api/getnew/'+this.id
    25. })
    26. this.detail = res.data.message[0]
    27. }
    28. },
    29. onLoad(options){
    30. this.id = options.id
    31. this.getNewsDetail()
    32. }
    33. }
    34. </script>
    35. <style lang="scss">
    36. .news_detail{
    37. font-size: 25rpx;
    38. padding:20rpx;;
    39. .title{
    40. text-align: center;
    41. width:710rpx;
    42. display: block;
    43. margin:20 0rpx;
    44. }
    45. .info{
    46. display: flex;
    47. justify-content: space-between;
    48. margin:30rpx;
    49. }
    50. }
    51. </style>

    在main.js文件里面加入js全局变量

    1. import Vue from 'vue'
    2. import App from './App'
    3. import { myRequest} from './util/api.js'
    4. Vue.prototype.$myRequest = myRequest //全局方法
    5. Vue.filter('formatDate',(date)=>{
    6. const nDate = new Date(date)
    7. const year = nDate.getFullYear().toString().padStart(2,0)
    8. const month = nDate.getMonth().toString().padStart(2,0)
    9. const day = nDate.getDay().toString().padStart(2,0)
    10. return year+'-'+month+'-'+day
    11. })
    12. Vue.config.productionTip = false
    13. App.mpType = 'app'
    14. const app = new Vue({
    15. ...App
    16. })
    17. app.$mount()

    加入富文本解析html标签

    1. <view class='content'>
    2. <rich-text :nodes='detail.content'></rich-text>
    3. </view>Vue