Browse Source

修改标题可以换行

asd123a20 1 year ago
parent
commit
d12565bae8
2 changed files with 9 additions and 3 deletions
  1. 3 0
      src/store/index.js
  2. 6 3
      src/views/details.vue

+ 3 - 0
src/store/index.js

@@ -144,6 +144,9 @@ const mutations = {
     state.listTotal = payload.total;
   },
   contentsFetch(state, payload) {
+    if (payload.data.twoTitle) payload.data.twoTitle = payload.data.twoTitle.replace(/\n/g, '<br>');
+    if (payload.data.curtTitle) payload.data.curtTitle = payload.data.curtTitle.replace(/\n/g, '<br>');
+    if (payload.data.title) payload.data.title = payload.data.title.replace(/\n/g, '<br>');
     state.contentsItem = payload.data;
   },
   imgNewsFetch(state, payload) {

+ 6 - 3
src/views/details.vue

@@ -3,9 +3,9 @@
     <breadcrumb ref="breadcrumb"></breadcrumb>
     <div ref="detailsHome" class="detailsHome" v-if="contentsItem">
       <img class="thumbnail" v-if="isshow" :src="contentsItem.thumbnail">
-      <h4 class="title" v-if="contentsItem && contentsItem.twoTitle">{{ contentsItem.twoTitle }}</h4>
-      <h2 class="title">{{ contentsItem.title }}</h2>
-      <h4 class="title" v-if="contentsItem && contentsItem.curtTitle">{{ contentsItem.curtTitle }}</h4>
+      <h4 class="title" v-if="contentsItem && contentsItem.twoTitle" v-html="contentsItem.twoTitle"></h4>
+      <h2 class="title" v-html="contentsItem.title"></h2>
+      <h4 class="title" v-if="contentsItem && contentsItem.curtTitle" v-html="contentsItem.curtTitle"></h4>
       <!-- <span class="describe">{{ contentsItem.describe }}</span> -->
       <span class="date">
         发表时间: {{ contentsItem.date | dates }}
@@ -68,6 +68,9 @@ export default {
   filters: {
     dates(e) {
       return moment(e).format('YYYY-MM-DD');
+    },
+    setbr(val) {
+      return val.replace(/\n/g, '<br>');
     }
   }
 };