網站首頁 編程語言 正文
效果圖如下:
初始化展示兩行,超出顯示省略號,點擊查看全部,展示全部內容,點擊收起,恢復初始化狀態兩行
知識點:
- 展示兩行,用的css屬性:? ? display:?-webkit-box;???-webkit-box-orient:?vertical;? ? ?-webkit-line-clamp:?2;
- 利用clientHeight和scrollHeight的特性比較,來判斷內容是否溢出
摘自:https://blog.csdn.net/qq_35430000/article/details/80277587
以下是全部代碼:
我將其封裝成一個組件,這是組件的內容
<template>
<div>
<div class="question-des" ref="questionDes" v-if="!showMore">
{{ des }}
</div>
<div class="switchBtn" v-if="hasMore" @click="switchFn(1)">查看全部</div>
<div class="question-des_more" v-if="showMore">{{ des }}</div>
<div class="switchBtn" v-if="!hasMore && showMore" @click="switchFn(0)">
收起
</div>
</div>
</template>
<script>
export default {
props: ['des'],
data () {
return {
hasMore: false,
showMore: false
}
},
mounted () {
this.$nextTick(() => {
this.hasMore = this.$refs.questionDes.clientHeight < this.$refs.questionDes.scrollHeight
})
},
methods: {
switchFn (type) {
if (type) {
this.showMore = true
this.hasMore = false
} else {
this.showMore = false
this.hasMore = true
}
}
}
}
</script>
<style>
.question-des {
font-size: 12px;
padding: 5px 10px;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
white-space: wrap;
color: textLightGrey;
}
.question-des_more {
padding: 5px 10px;
color: textLightGrey;
font-size: 12px;
}
.switchBtn {
font-size: 12px;
color: #5fbefe;
text-align: right;
margin-top: -8px;
margin-bottom: 6px;
}
</style>
引用方法如下:
原文鏈接:https://blog.csdn.net/Crazy_GirlLL/article/details/115907928
相關推薦
- 2022-07-12 jmm內存模型及volatile實現原理
- 2022-10-03 Objective-C?const常量的優雅使用方法_IOS
- 2022-10-03 Go?Excelize?API源碼閱讀Close及NewSheet方法示例解析_Golang
- 2022-08-17 R語言UpSet包實現集合可視化示例詳解_R語言
- 2022-04-25 C#關于Func和Action委托的介紹詳解_C#教程
- 2022-11-12 Python創建SQL數據庫流程逐步講解_python
- 2022-10-31 C#?如何調用python腳本_C#教程
- 2021-12-08 教你如何在windows?10家庭版上安裝docker_docker
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支