網(wǎng)站首頁 編程語言 正文
效果圖如下:
初始化展示兩行,超出顯示省略號,點擊查看全部,展示全部內(nèi)容,點擊收起,恢復初始化狀態(tài)兩行
知識點:
- 展示兩行,用的css屬性:? ? display:?-webkit-box;???-webkit-box-orient:?vertical;? ? ?-webkit-line-clamp:?2;
- 利用clientHeight和scrollHeight的特性比較,來判斷內(nèi)容是否溢出
摘自:https://blog.csdn.net/qq_35430000/article/details/80277587
以下是全部代碼:
我將其封裝成一個組件,這是組件的內(nèi)容
<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
相關(guān)推薦
- 2022-09-19 Python?Numpy中ndarray的常見操作_python
- 2022-10-29 C#?CLR學習?C++使用namespace實例詳解_C 語言
- 2022-01-29 調(diào)用存儲命令:將sqlserver表中的數(shù)據(jù)導出sql語句或生成insert into語句
- 2022-06-09 ASP.NET?Core使用EF創(chuàng)建模型(索引、備用鍵、繼承、支持字段)_實用技巧
- 2022-07-24 .Net行為型設(shè)計模式之職責鏈模式(Chain?of?Responsibility)_基礎(chǔ)應用
- 2022-04-21 Python的基礎(chǔ)語法和輸入輸出函數(shù)你都了解嗎_python
- 2022-02-25 Linux下臨時和永久修改主機名
- 2022-09-16 C#數(shù)據(jù)庫操作的示例詳解_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支