vue控制多行文字展開收起的實現(xiàn)示例
更新時間:2019年10月11日 11:11:50 作者:馬優(yōu)晨
這篇文章主要介紹了vue控制多行文字展開收起的實現(xiàn)示例(也叫控制文字展開隱藏),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
這里講一下,如何使用vue控制多行文字展開收起(也叫控制文字展開隱藏)。
效果:
這里設置了控制三行,如果超過三行會展示,“顯示更多” 超出文字顯示省略號。點擊“顯示更多”會展開所有文案,按鈕變成“收起”
(未超出三行的時候)
(展開)
(收起)
代碼實現(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="需要傳遞的文字數(shù)據(jù)"></Spread>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue封裝echarts組件,數(shù)據(jù)動態(tài)渲染方式
這篇文章主要介紹了vue封裝echarts組件,數(shù)據(jù)動態(tài)渲染方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12Vuejs仿網(wǎng)易云音樂實現(xiàn)聽歌及搜索功能
這篇文章主要介紹了Vuejs仿網(wǎng)易云音樂實現(xiàn)聽歌及搜索功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-03-03vuex刷新頁面后如何解決丟失store的數(shù)據(jù)問題
這篇文章主要介紹了vuex刷新頁面后如何解決丟失store的數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12