当前位置:网站首页>Uni app, the text implementation expands and retracts the full text
Uni app, the text implementation expands and retracts the full text
2022-06-26 03:43:00 【yyxhzdm】
effect :

Ideas :
1. According to the layout displayed by text , The approximate number of words that can be displayed per line .( The instance is roughly per line 26 A word )
2. When the page is loaded first , Judge whether the number of custom lines is exceeded according to the total length of the text , To process the corresponding data , Extra custom lines , Intercept the corresponding number of words for display
Code and explanation :
1. Set parameters (script in )

isShowAllContent: Yes, both “ The full text ” written words
txt_content: All text content
tempContent: Text content displayed after processing
2. Enter the page to process data
onLoad() {
var _this = this
var txtCntIndex = _this.txt_content.length
if (txtCntIndex > 52) {
_this.isShowAllContent = true
_this.tempContent = _this.txt_content.substr(0, 51) + "..."
} else {
_this.isShowAllContent = false
_this.tempContent = _this.txt_content
}
},

3. Layout
<!-- The article is put away with the full text -->
<text class="yd-content">{ {tempContent}}</text>
<template v-if="txt_content !== null && txt_content.length > 52">
<text class="yd-quanwen" v-if="isShowAllContent" @click="toggleDescription"> The full text </text>
<text class="yd-quanwen" v-else @click="toggleDescription"> Retract </text>
</template>

4.“ The full text ” or “ Retract ” Button click event handling
// Full text and collapse
toggleDescription: function() {
var _this = this
if (_this.isShowAllContent) {
_this.isShowAllContent = false
_this.tempContent = _this.txt_content
} else {
_this.isShowAllContent = true
_this.tempContent = _this.txt_content.substring(0, 51) + "..."
}
},

The overall code :

complete , Realize the expansion and collapse of text !!!
边栏推荐
- mysql存储过程
- Kotlin learning apply plugin: 'kotlin Android extensions‘
- Click event
- Is it safe for Caicai securities to open an account in 2022?
- Navicat16 wireless trial
- Popupwindow utility class
- 给网站添加“开放搜索描述“以适配浏览器的“站点搜索“
- Analysis of the multiple evaluation system of children's programming
- Group counting notes - instruction pipeline of CPU
- 图扑软件数字孪生海上风电 | 向海图强,奋楫争先
猜你喜欢
![[paper notes] supersizing self supervision: learning to grasp from 50K tries and 700 robot hours](/img/fe/f8208747e03133f4a66e73598409d5.png)
[paper notes] supersizing self supervision: learning to grasp from 50K tries and 700 robot hours

点击事件

The role of children's programming in promoting traditional disciplines in China

Todolist incomplete, completed

小米电视的网页和珠宝的网页

Uni app custom selection date 2 (September 16, 2021)

Hardware creation principle of campus maker space

Problems encountered in project deployment - production environment

Cloud Computing Foundation -0

类图
随机推荐
拖放
Various errors in kitti2bag installation
Butterknife unbinder uses flashback in fragment and viewpager
mysql存储过程
进程之间的通信方式
【哈希表】改进,拉链法哈希结构——直接用两个索引查找,不用每次都hash和%一遍
Analysis of technological changes in social robots
Where is it safe to open a fund account?
Worm copy construction operator overload
QT compilation error: unknown module (s) in qt: script
progress bar
多媒体元素,音频、视频
How to prepare for a moving wedding
Request object, send request
Double carbon bonus + great year of infrastructure construction 𞓜 deep ploughing into the field of green intelligent equipment for water conservancy and hydropower
双碳红利+基建大年 | 图扑深耕水利水电绿色智能装备领域
Class diagram
Multimedia elements, audio, video
MySQL增删查改(进阶)
云计算基础-0