vue控制多行文字展開(kāi)收起的實(shí)現(xiàn)示例
這里講一下,如何使用vue控制多行文字展開(kāi)收起(也叫控制文字展開(kāi)隱藏)。
效果:
這里設(shè)置了控制三行,如果超過(guò)三行會(huì)展示,“顯示更多” 超出文字顯示省略號(hào)。點(diǎn)擊“顯示更多”會(huì)展開(kāi)所有文案,按鈕變成“收起”

(未超出三行的時(shí)候)

(展開(kāi))

(收起)
代碼實(shí)現(xiàn):
<template>
<div>
<p class="m-content overflow-line" id="J_description">{{introduce}}</p>
<button type="button" class="btn-more" v-if="isShowMore" id="J_btnmore" @click="showmoreDesc($event)">查看更多</button>
</div>
</template>
<script>
export default {
name: 'Spread',
data() {
return {
isShowMore: false,
isDescStatus: true,
introduce: ""
};
},
props: {
mes2: {
type: String,
default: ""
}
},
methods: {
showmoreDesc(e) {
let el = e.currentTarget;
el.previousElementSibling.classList[!this.isDescStatus ? 'add' : 'remove']('overflow-line');
el.classList[this.isDescStatus ? 'add' : 'remove']('more-collapse');
el.innerHTML = !this.isDescStatus ? '查看更多' : '收起';
this.isDescStatus = !this.isDescStatus;
that.isShowMore = true;
}
},
watch: {
mes2(val) {
this.introduce = val;
if (this.introduce.length > 75) {
this.isShowMore = true;
}
}
}
};
</script>
<style lang="less" scoped>
.m-content {
&.overflow-line {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
}
.btn-more {
color: #fff;
float: right;
color: #5383E7;
position: relative;
margin-top: rc(5);
padding-right: rc(33);
&.more-collapse {
&::after,
&::before {
top: 2px;
transform: rotate(180deg);
}
&::before {
top: 4px;
}
}
&::after,
&::before {
width: 0;
height: 0;
content: '';
position: absolute;
right: 0;
top: 7px;
border: rc(12) solid transparent;
}
&::after {
border-top-color: #5383E7;
z-index: 1;
}
&::before {
border-top-color: #1c2239;
z-index: 2;
top: 5px;
}
}
</style>
使用組件
<Spread :mes2="需要傳遞的文字?jǐn)?shù)據(jù)"></Spread>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue element-ul實(shí)現(xiàn)展開(kāi)和收起功能的實(shí)例代碼
- Vue 中文本內(nèi)容超出規(guī)定行數(shù)后展開(kāi)收起的處理的實(shí)現(xiàn)方法
- vue 點(diǎn)擊展開(kāi)顯示更多(點(diǎn)擊收起部分隱藏)
- vue.js 實(shí)現(xiàn)點(diǎn)擊展開(kāi)收起動(dòng)畫(huà)效果
- 基于vue展開(kāi)收起動(dòng)畫(huà)的示例代碼
- vue實(shí)現(xiàn)點(diǎn)擊展開(kāi)點(diǎn)擊收起效果
- vue和react等項(xiàng)目中更簡(jiǎn)單的實(shí)現(xiàn)展開(kāi)收起更多等效果示例
- Vue實(shí)現(xiàn)文本展開(kāi)收起功能
相關(guān)文章
vue封裝echarts組件,數(shù)據(jù)動(dòng)態(tài)渲染方式
這篇文章主要介紹了vue封裝echarts組件,數(shù)據(jù)動(dòng)態(tài)渲染方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
vue3 響應(yīng)式對(duì)象如何實(shí)現(xiàn)方法的不同點(diǎn)
這篇文章主要介紹了vue3 響應(yīng)式對(duì)象如何實(shí)現(xiàn)方法的不同點(diǎn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05
VUE項(xiàng)目中引入vue-router的詳細(xì)過(guò)程
vue-router 也叫 vue 路由,根據(jù)不同的路徑,來(lái)執(zhí)行不同的組件,這篇文章主要介紹了VUE項(xiàng)目中引入vue-router,需要的朋友可以參考下2023-05-05
解決vue自定義指令導(dǎo)致的內(nèi)存泄漏問(wèn)題
這篇文章主要介紹了解決vue自定義指令導(dǎo)致的內(nèi)存泄漏問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08
Vue項(xiàng)目中最新用到的一些實(shí)用小技巧
這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中最新用到的一些實(shí)用小技巧,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11
Vuejs仿網(wǎng)易云音樂(lè)實(shí)現(xiàn)聽(tīng)歌及搜索功能
這篇文章主要介紹了Vuejs仿網(wǎng)易云音樂(lè)實(shí)現(xiàn)聽(tīng)歌及搜索功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03
vue基于viewer實(shí)現(xiàn)的圖片查看器功能
這篇文章主要介紹了vue基于viewer實(shí)現(xiàn)的圖片查看器的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04
vuex刷新頁(yè)面后如何解決丟失store的數(shù)據(jù)問(wèn)題
這篇文章主要介紹了vuex刷新頁(yè)面后如何解決丟失store的數(shù)據(jù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12

