vue实现点击展开全部,点击收起全部

16 篇文章 0 订阅

1.html代码

         <div class="richTxt" :class="is_show ? 'new_detail' : 'work_detail'">
              <img src="@/assets/images/bg-recommend.png" alt />//测试的一张图片本地图片
          </div>         
          <div class="look_all"  @click="is_show=!is_show">
            <p>{{words}}</p>
            <img
              class="nlook_img"
              :class="is_show ? 'up_img' : 'nlook_img'"
              src="@/assets/images/upkods.png"
              alt
            />//是下拉的icon可自行定义
          </div>

2.在data中定义

 data() {
    return {
      is_show: false,
  },
}

3.vue计算属性

computed: {
    words() {
      if (this.is_show === false) {
        return "查看全部";
      } else if (this.is_show === true) {
        return "收起全部";
      } else if (this.is_show === "") {
        return null;
      } else {
        return null;
      }
    },
  },

4.style样式

.richTxt img {
  display: block;
  width: 100%;
  height: 400px;
  margin-top: 10px;
}
.new_detail {
  font-size: 16px;
  padding: 0 10px;
  height: 100%;
  transition: height 2s linear;
}
.work_detail {
  width: 100%;
  overflow: hidden; /**隐藏超出的内容**/
  padding: 0 10px;
  height: 120px;
}
.work_detail img {
  display: block;
  width: 100%;
  overflow: hidden; /**隐藏超出的内容**/
}
.new_detail img {
  display: block;
  width: 100%;
  height: 100%;
}
.look_all {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto;
  font-size: 16px;
  color: rgb(66, 69, 238);
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  padding: 10px;
  border-radius: 5px;
  background: #fff;
}
.look_all .nlook_img {
  display: block;
  width: 20px;
  height: 20px;
  margin-left: 5px;
  transition-duration: 500ms;
}
.look_all .up_img {
  transform: rotate(180deg);
  transition-duration: 500ms;
}

5.效果图

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值