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
Table of contents vue2.x vue3.x tiny-emitter plug...
Test the efficiency of deleting a large number of...
Isolation of process address spaces is a notable ...
Table of contents Preface Core - CancelToken Prac...
Table of contents 1. Introduction to SQL Injectio...
Table of contents Preface 1. Nginx installation 1...
Table of contents 1. Custom import in packaging t...
1. Create a database: create data data _name; Two...
ab command principle Apache's ab command simu...
1. First go to the official website https://www.p...
nohup command: If you are running a process and y...
1. Download https://dev.mysql.com/downloads/mysql...
Table of contents Preface Introduction to Bezier ...
Table of contents I. Overview 2. pt-archiver main...
Today I received a disk warning notification from...