
.topic_cont_text{ padding: 30upx; colof: #999; background: #E1FFFF; max-height: 130upx; overflow: hidden; word-break: break-all; /* break-all(允許在單詞內換行。) */ text-overflow: ellipsis; /* 超出部分省略號 */ display: -webkit-box; /** 對象作為伸縮盒子模型顯示 **/ -webkit-box-orient: vertical; /** 設置或檢索伸縮盒對象的子元素的排列方式 **/ -webkit-line-clamp: 2; /** 顯示的行數 **/ }
<view class="topic_content"> <view class="topic_cont_text"> <template v-if="showText"> {{topicDetail.description}} <text v-if="topicDetail.description !== null && topicDetail.description.length > 140" class="full_text" @click="toggleDescription">收起</text> </template> <template v-else> {{topicDetail.description.substr(0, 140)}} <text v-if="topicDetail.description !== null && topicDetail.description.length > 140" class="full_text" @click="toggleDescription">全文</text> </template> </view> </view> // 全文展開收起 toggleDescription (num) { this.showText = !this.showText },
轉載:https://blog.csdn.net/qq_41287423/article/details/98597276