1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Vue2.0 组件文本超出3行显示... 点击查看更多可以查看全部内容(展开收起)

Vue2.0 组件文本超出3行显示... 点击查看更多可以查看全部内容(展开收起)

时间:2020-06-10 18:09:58

相关推荐

Vue2.0 组件文本超出3行显示... 点击查看更多可以查看全部内容(展开收起)

效果

<template><div ref="txttype" class="bottom"><div :class="hidetext==true?'room_intro showEllipsis':'room_intro'">{{content}}</div><span class="btnWrap" v-if="nomore" @click="lookmore"><a class="more">{{moretext}}<i :class="hidetext==false?'el-icon-arrow-up':'el-icon-arrow-down'"></i></a></span></div></template><script>export default ({name: 'ellipsisText',props: {//父组件传过来的文本content: {type: String,default: ''},},data() {return {moretext: '查看更多',nomore: true,hidetext: false,}},mounted() {//通过ref获取对应dom节点的高度,注意20为单行时的高度let hei = this.$refs.txttype.clientHeight;//当获取的高度大于20时,即当前文本为多行,设置添加收起文本的class,//当获取的高度等于20时,隐藏查看更多按钮if (hei > 20) {this.hidetext = truethis.nomore = true} else if (hei == 20) {this.nomore = false}},methods: {//查看更多lookmore() {this.hidetext = !this.hidetextthis.moretext = this.hidetext == true ? '查看更多' : '收起'},}})</script><style lang="scss" scoped>.bottom {margin-top: 12px;position: relative;// .Flex();.room_intro {flex:1;font-size: 14px;font-weight: 400;line-height: 20px;text-align: justify;}.showEllipsis{// 文本溢出超出两行显示省略号overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 3;line-clamp: 3;-webkit-box-orient: vertical;}.btnWrap {align-self: flex-end;cursor: pointer;}}</style>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。