收起展开
<template><view class="font30 color000 mL30 mR30"><text :class="showFullText ? '' : 'clamp-text'">{{ text }}</text><view v-if="showToggleBtn && text.length > 42" @click="toggleShowFullText">{{ showFullText ? '收起' : '全文' }}</view></view>
</template><script>export default {data() {return {text: '我与春风皆是客,你携秋水揽星河。我与春风皆是客,你携秋水揽星河。我与春风皆是客,你携秋水揽星河。我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客我与春风皆是客,你携秋水揽星河。我与春风皆是客。',showFullText: false};},computed: {showToggleBtn() {return this.text.length > 42;}},methods: {toggleShowFullText() {this.showFullText = !this.showFullText;}}};
</script><style>.clamp-text {display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;text-overflow: ellipsis;}view {color: #007aff;}
</style>