<template>
<div :class="showTotal ? 'total-introduce' : 'detailed-introduce'">
<div class="intro-content" :title="introduce" ref="desc">
<span class="merchant-desc" v-if="introduce">{{ introduce }}</span>
<div class="unfold" @click="showTotalIntro" v-if="showExchangeButton">
<p>{{ exchangeButton ? "展开" : "收起" }}</p>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
introduce:
"1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊1aaaaAA啊啊啊啊啊", // 简介
showTotal: true, // 简介全部显示
exchangeButton: false, // 展开/收起文字改变
showExchangeButton: false, // 是否显示 展开/收起 文字
};
},
created() {
this.$nextTick(() => {
debugger
if (!this.$refs.desc) {
return;
}
const descHeight = window
.getComputedStyle(this.$refs.desc)
.height.replace("px", "");
if (parseInt(descHeight) * 2 > 139) {
this.showExchangeButton = true;
this.exchangeButton = true;
this.showTotal = false;
} else {
this.showExchangeButton = false;
this.showTotal = true;
}
});
},
methods: {
showTotalIntro() {
this.showTotal = !this.showTotal;
this.exchangeButton = !this.exchangeButton;
},
},
};
</script>
<style lang="less" scoped>
.total-introduce {
height: auto;
overflow: hidden;
color: #666;
margin-top: 30px;
.intro-content {
.merchant-desc {
width: 100%;
}
}
.unfold {
display: block;
float: right;
width: 80px;
height: 40px;
z-index: 8;
text-align: center;
p {
margin: 0;
line-height: 40px;
color: #0098ff;
}
}
}
.detailed-introduce {
color: #666;
position: relative;
overflow: hidden;
margin-top: 30px;
.intro-content {
//最大高度设为3倍的行间距
max-height: 50px;
word-wrap: break-word;
word-break: break-all;
background-color: #fff;
color: #fff;
overflow: hidden;
.merchant-desc {
width: 100%;
line-height: 40px;
}
&::after,
&::before {
content: attr(title);
position: absolute;
left: 0;
top: 0;
width: 100%;
color: #666;
}
&::before {
display: block;
overflow: hidden;
z-index: 1;
max-height: 80px;
background: #fff;
}
&::after {
display: -webkit-box;
-webkit-box-orient: vertical;
height: 120px;
// 截取行数
-webkit-line-clamp: 3;
text-overflow: ellipsis;
box-sizing: border-box;
// 行首缩进字符数,值为[(截取行数-1)*尾部留空字符数]
text-indent: -6em;
// 尾部留空字符数
padding-right: 3em;
}
.unfold {
z-index: 8;
width: 80px;
// height: 40px;
outline: 0;
position: absolute;
right: 0;
bottom: 0;
text-align: center;
p {
margin: 0;
color: #0098ff;
}
}
}
}
</style>
前端长文本展开收起
最新推荐文章于 2023-12-25 18:26:24 发布