uniapp,文字超出几行显示省略号...,展开显示更多

效果图:

在这里插入图片描述
在这里插入图片描述

代码:

<template>
	<view class="text-container">
			<text class="text-content" @click="showDetail">{{ text }}</text>
			<text v-if="showMore" class="view-detail" @click="showDetail" style="color: #457AE6;">查看详情</text>
			<text v-if="showText&&!showMore" class="view-detail" @click="showShrink" style="color: #457AE6;">收起</text>
	</view>
</template>

<script>
	export default {
		mounted() {
			this.text = '这里是一段很长的文本内容,我们需要对超出一定长度的见到过伤筋动骨几十个地级市的世界观的几十个地级市高端就是给大家圣诞节后视镜的呼声结婚的结婚建设大街的好时机回到家';
			this.textyl = this.text
			this.checkTextLength();
		},
		data() {
			return {
				text: '',//剪切之后的文字
				textyl:'',//原来的字符
				showMore: false,//判断显示查看或者收起   小于40字不展示
				textlength: false,//判断是否点击详情 true为点击详情 false为点击收起
				showText:false//收起文字的显示隐藏
			};
		},
		computed: {
		
		},
		methods: {
			checkTextLength() {
				if (this.text.length > 40 && !this.textlength) {
					this.showMore = true;
					this.showText = false
					this.text = this.text.substring(0, 40) + '...';
				} else {
					this.showText= true
					this.showMore = false;
					this.textlength = false
					this.text = this.textyl
				}
			},
			showDetail() {
				if (this.showMore) {
					this.textlength = true
					this.checkTextLength()
				}
			},
			showShrink() {
				if (this.showText) {
					this.textlength = false
					this.checkTextLength()
				}
			},
		}
	};
</script>

<style>
	.clamp-text {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	view {
		color: #007aff;
	}
</style>

相关推荐

  1. 行文本超出显示省略号

    2024-04-05 01:38:02       42 阅读
  2. css文本超长溢出显示省略号 ...

    2024-04-05 01:38:02       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-05 01:38:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-05 01:38:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-05 01:38:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-05 01:38:02       20 阅读

热门阅读

  1. IO流c++

    IO流c++

    2024-04-05 01:38:02      14 阅读
  2. 关于在PyCharm中使用虚拟环境

    2024-04-05 01:38:02       16 阅读
  3. GCC -Wl参数详解

    2024-04-05 01:38:02       19 阅读
  4. 如何通过pciehp管理NVMe SSD电源状态?

    2024-04-05 01:38:02       32 阅读
  5. 英国和美国签署开发人工智能安全测试协议

    2024-04-05 01:38:02       15 阅读
  6. Python语言例题集(010)

    2024-04-05 01:38:02       15 阅读