Folding display multi-line text component
First, the code <template> <div class="text-expand" ref="textExpand"> <div v-if="!(showPopover && showPopoverJudge)"> <span class="text-expand-content" :style="expandStyle"> {{ (text === null || text === undefined || text === '') ? '--' : text }} </span> <div class="expander"> <span v-if="showBtn && showBtnJudge" > <span v-if="!showFull" class="action action-expand" @click.stop="showFullFn(true)" > Expand<i v-if="showBtnIcon" class="iconfont iconxiajiantou" /> </span> <span v-else class="action action-pack" @click.stop="showFullFn(false)" > Hide <i v-if="showBtnIcon" class="iconfont iconshangjiantou" /> </span> </span> </div> </div> <el-popover v-else :placement="popoverPlace" trigger="hover"> <div class="popover-content"> {{ text }} </div> <span class="text-expand-content" :style="expandStyle" slot="reference">{{ text }}</span> </el-popover> </div> </template> <script> export default { name: "TextExpand", props: { text: { // text content type: String, default: () => '' }, expand: { // Fold and display the number of lines type: Number, default: () => 3 }, showBtn: { // Expand, collapse button type: Boolean, default: true }, showBtnIcon: { // expand, collapse icon type: Boolean, default: true }, showPopover: { // popover displays full text type: Boolean, default: false }, popoverPlace: { // popover position type: String, default: 'bottom' } }, data () { return { showFull: false, // Whether to display the full text expandStyle: '', showBtnJudge: false, //Judge whether to fold and display the button showPopoverJudge: false //Judge whether to fold and display the popover } }, watch: text: function (val) { this.judgeExpand() } }, mounted () { this.judgeExpand() }, methods: { showFullFn (value) { this.expandStyle = value ? '' : `display: -webkit-box;word-break: break-all;-webkit-line-clamp: ${this.expand};-webkit-box-orient: vertical;text-overflow: ellipsis;overflow: hidden;` this.showFull = value }, judgeExpand () { //Judge whether to collapse this.$nextTick(() => { const { expand } = this; const textExpandStyle = window.getComputedStyle(this.$refs.textExpand) const textExpandHeight = parseFloat(textExpandStyle.height) //Get the total height const textExpandLineHeight = parseFloat(textExpandStyle.lineHeight) //Get the line height // Calculate the line height const rects = Math.ceil(textExpandHeight / textExpandLineHeight) if (rects <= expand) { // No need to fold and display this.showBtnJudge = false this.showPopoverJudge = false } else { this.showBtnJudge = true this.showPopoverJudge = true this.expandStyle = `display: -webkit-box;word-break: break-all;-webkit-line-clamp: ${this.expand};-webkit-box-orient: vertical;text-overflow: ellipsis;overflow: hidden;` } }) } } } </script> <style lang="less" scoped> .text-expand{ &-content{ word-break: break-all; white-space: pre-wrap; } .expander { text-align: left; margin-top: 6px; .action { display: inline-block; font-size: 14px; color: #0281F0; cursor: pointer; i { display: inline; font-size: 12px; } } .action.action-pack { margin-left: 0; } } } .popover-content{ max-width: 40vw; max-height: 30vh; overflow: hidden; word-break: break-all; overflow-y: auto; } </style> usage
This is the end of this article about the vue folding display multi-line text component. For more related vue folding display multi-line text component content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Common structural tags in XHTML
>>: Analysis of the implementation process of Docker intranet penetration frp deployment
1. Add MySQL Yum repository MySQL official websit...
Building web pages that comply with Web standards ...
A common development need is that we want to coll...
<br />The frame structure allows several web...
1 Introduction Kong is not a simple product. The ...
In normal development, we usually use convex roun...
1. Rounded border: CSS CodeCopy content to clipbo...
1. useState: Let functional components have state...
Table of contents 1. Operation elements 1.1. Chan...
Multi-way search tree Height of a complete binary...
1. What is it? MySQL is the most popular relation...
This article shares the specific code of js to im...
1. Who is tomcat? 2. What can tomcat do? Tomcat i...
CSS3 achieves cool 3D rotation perspective 3D ani...
Introduction to border properties border property...