在页面只显示6张图片

一.效果如下:

 二.思路如下:

1.首先遍历后端传过来的进行遍历(这样图片可能不止六张)

2.在获取数据进行判断  大于6做一个处理

3.大于6的 更多要显示出来

4.点击更多 在把其他的显示出来

看到这个--------

是不是想骂人--------

这都是什么玩意--------

三.上栗子:

在页面上写代码:

 <div class="clearfix" style="display: flex; flex-wrap: wrap">
             <--这里是遍历-->
                  <div
                    v-for="(item, index) in fileList"
                    :key="index"
                    style="margin-left: 10px; margin-top: 10px"
                  >
                   <--这里是vue引用全屏插件  翻我的csdn可以查到怎样用-->
                    <img
                      v-image-preview
                      :src="item.url"
                      style="width: 100px; height: 100px"
                    />
                     <--添加更多-->
                    <span class="moreImg" v-if="flag" @click="moreImge"
                      >更多</span
                    >
                  </div>
                </div>

逻辑部分代码:

if (this.dataproject.conversationImgUrl.length > 0) {
        var fileListArr1 = [];
        this.fileList = this.$imageUtil.handleImages(
          this.dataproject.conversationImgUrl
        );
        this.imgArr = this.$imageUtil.handleImages(
          this.dataproject.conversationImgUrl
        );
        if (this.fileList.length >= 6) {
          this.flag = true;
          // 图片长度超出6个,截取数据长度 限制6个
          this.fileList.forEach((item, index) => {
            if (index < 5) {
              fileListArr1.push(item);
            }
          });
          this.fileList = fileListArr1;
        } else {
          this.flag = false;
        }
      }

 点击更多的时候,

moreImge() {
      this.flag = false;
      this.fileList = this.imgArr;
    },

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值