vue实现内容过多隐藏,点击显示

news/2024/7/10 3:19:56 标签: javascript, vue

html
Description是介绍的具体内容

javascript"><div class="introduce">介绍:{{Description}}</div>
<div class="more" v-if="!isShowAll && isRoll" @click="toDown">展开<i class="iconfont icon-up2-copy"></i></div>
<div class="more" v-if="!isShowAll && !isRoll" @click="toUp">收起<i class="iconfont icon-up2"></i></div>

css

javascript">.introduce {
    width: 400px;
    font-size: 14px;
    font-weight: normal;
    word-wrap:break-word;
}
.more {
    position: absolute;
    bottom: -20px;
    right: 0px;
    font-size: 14px;
    font-weight: normal;
    cursor: pointer;
    color: rgb(26, 76, 212);
}

data部分
isShowAll的值和介绍内容长度有关 用来控制显示和隐藏按钮的

javascript">    data() {
        return {
            // 歌单信息
            playListDetail: {},
            // 歌单介绍是否显示完整
            isShowAll: true,
            // 歌单介绍是否是收起状态
            isRoll: true,
            Description: null
        }
    },

watch部分
当内容大于200个字符的时候,对内容进行截取,并且显示按钮

javascript">    watch: { 
        'playListDetail.description': function() {
            if (this.playListDetail.description.length > 200) {
                this.Description = this.playListDetail.description.substr(0, 200);
                this.isShowAll = false;
            } else {
                this.isShowAll = true;
            }
        }
     },

methods

javascript">        // 点击按钮展开歌单介绍
        toDown() {
            this.Description = this.playListDetail.description;
            this.isRoll = false;
        },
        // 点击按钮收起歌单介绍
        toUp() {
            this.Description = this.playListDetail.description.slice(0, 200) + '...';
            this.isRoll = true;
        },

结果展示

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


http://www.niftyadmin.cn/n/734983.html

相关文章

lvs(1) - 基础概念

一、集群 系统扩展方式有两种, 一种是向上扩展(scale up), 通过提升CPU规格、磁盘空间、内存空间等方式来提高性能; 第二种就是通过横向扩展(scale out), 通过将一组相互独立、通过高速网络互连的计算机(这些计算机都提供相同的服务)组成一个组, 并以单一系统模式进行管理. 当客…

vue路由router

1 路由数据 当我们在vue中注册了路由之后&#xff0c;每一个组件都会具有两个属性&#xff1a;$route, $router $router 表示路由实例&#xff0c;包含一些切换路由的方法 push 进入一个新页面 back 返回上一个页面 go 返回第一个页面 replace 替换当前的页面 forward 进入下…

python3+requests库框架设计07-生成测试报告

使用HTMLTestRunner可以生成测试报告。HTMLTestRunner是unittest模块下的一个拓展&#xff0c;原生的生成报告样式比较丑&#xff0c;GitHub上有大佬优化过后的版本&#xff1a;GitHub地址。下载之后解压应该是这样的 我们需要使用的是HTMLTestRunnerCN.py和EN.py 这两个。一个…

css换行,溢出显示省略号

1 css强制换行 text-overflow: ellipsis; white-space:nowrap; overflow:hidden;

一个关于柯里化函数的实现解析

本篇内容主要参考了以下文章&#xff1a;从 sum(2)(3) sum(2, 3) 到实现柯里化函数JavaScript专题之函数柯里化 柯里化定义 在数学和计算机科学中&#xff0c;柯里化是一种将使用多个参数的一个函数转换成一系列使用一个参数的函数的技术。一个柯里化函数的实现 在上面两篇文章…

vue监听路由参数变化,路由变化的时候刷新数据

1 vue监听路由参数变化&#xff0c;路由变化的时候刷新数据 path的路径还是本页面&#xff0c;通过query传入query数据&#xff0c;但是页面数据没有刷新 <router-link tag"div" :to"{path:/playList,query:{id:item.id}}"></router-link>所…

python成长之路一

1&#xff0c;计算机基础 CPU&#xff1a;中央处理器&#xff0c;相当于人类的大脑&#xff0c;运算中心&#xff0c;控制中心。内存&#xff1a;暂时储存数据&#xff0c;与CPU交互&#xff0c;8G&#xff0c;16G&#xff0c;32G&#xff0c;64G 优点&#xff1a;读取速度快。…

vue路由router传参数方式

params、query是什么&#xff1f; params&#xff1a;/router1/:id &#xff0c;/router1/123&#xff0c;/router1/789 ,这里的id叫做params query&#xff1a;/router1?id123 ,/router1?id456 ,这里的id叫做query。 1 调用this.$router.push实现携带参数的跳转 this.$ro…