一、组件封装
<template>
<view class="multiline">
<view class="info">
<view :class="{hide:!iSinfo}" :style="!iSinfo?computedStyle:''">
<view :style="{ color: textColor,fontWeight:fontWeight,fontSize:fontSize + 'rpx'}">
{{content}}
</view>
</view>
<text @tap="showinfo" v-if="!iSinfo"
:style="{ color: showinfotextColor,fontWeight:showinfoFontWeight,fontSize:showinfoSize + 'rpx'}">展开</text>
</view>
<text @tap="showinfo" v-if="iSinfo" class="hidebtn"
:style="{ color: showinfotextColor,fontWeight:showinfoFontWeight,fontSize:showinfoSize + 'rpx'}">收起</text>
</view>
</template>
<script>
export default {
props: {
content: {
type: String,
default: ""
},
linesCount: {
type: [Number, String],
default: 2
},
textColor: {
type: String,
default: "#333333"
},
fontWeight: {
type: [Number, String],
default: 400
},
fontSize: {
type: [Number, String],
default: 24
},
showinfoSize: {
type: [Number, String],
default: 24
},
showinfotextColor: {
type: String,
default: "#333333"
},
showinfoFontWeight: {
type: [Number, String],
default: 400
},
},
data() {
return {
iSinfo: false,
};
},
mounted() {},
computed: {
computedStyle() {
const style = `-webkit-line-clamp: ${this.linesCount};`;
return style;
}
},
methods: {
showinfo() {
this.iSinfo = !this.iSinfo
}
},
};
</script>
<style lang="scss" scoped>
.multiline{
display: flex;
flex-direction: column;
background-color: #fff;
position: relative;
.info {
display: flex;
flex-direction: column;
view {
text-align: justify;
word-break: break-word;
background-color: #fff;
}
text {
width: 70px;
display: flex;
justify-content: flex-end;
align-items: center;
background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 50%);
color: #0078FF;
position: absolute;
bottom: 0rpx;
right: 0rpx;
}
}
}
.hidebtn {
display: flex;
flex: 1;
justify-content: flex-end;
}
.hide {
word-break: break-word;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
}
</style>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
二、使用
<multiline-expansion content="uniapp实现多行文本溢出超过指定行数 展开 收起uniapp实现多行文本溢出超过指定行数 展开 收起uniapp实现多行文本溢出超过指定行数 展开 收起uniapp实现多行文本溢出超过指定行数 展开 收起"></multiline-expansion>