You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<template> <view class="lf-m-l-32 lf-m-r-32"> <view> <view class="lf-font-32 lf-color-333 lf-m-t-30 lf-m-b-20"> {{title_content.title}} </view> <view class="lf-flex lf-m-b-24"> <view class="lf-color-999 lf-font-24" v-if="title_content.updated_at"> 发布于<text class="lf-m-l-10">{{title_content.updated_at}}</text> </view> <view class="lf-color-999 lf-font-24 lf-m-l-30" v-if="title_content.author"> 作者<text class="lf-m-l-10">{{title_content.author}}</text> </view> </view> </view> <rich-text :nodes="formatRichText(content)" v-if="$isRight(content)"></rich-text> <lf-nocontent v-else></lf-nocontent> <!-- 回到顶部 --> <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top> </view></template>
<script> export default { data(){ return { content: '', news_id: 0, title_content: '' } }, onLoad(e){ this.news_id = e.news_id if(this.news_id) { this.getData(); } }, methods: { // 富文本处理
formatRichText(richText){ if(richText != null){ let newRichText= richText.replace(/<img[^>]*>/gi, function(match, capture){ match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); return match; }); newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){ match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;'); return match; }); newRichText = newRichText.replace(/<br[^>]*\/>/gi, ''); newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"'); return newRichText; }else{ return null; } }, getData(){ this.$http(this.API.API_MESSAGEDETAILS,{id: this.news_id}).then(res => { this.content = res.data?.content; this.title_content = res.data console.log(this.content) }) } } }</script>
<style lang="scss" scoped="scoped"> </style>
|