(H5轮播)vue一个轮播里显示多个内容/一屏展示两个半内容

效果图 :

html:

复制代码
  <div class="content">
          <van-swipe
            class="my-swipe com-long-swipe-indicator"
            :autoplay="2500"
            indicator-color="#00C4FF"
          >
            <van-swipe-item
              class="flex-row-wrap"
              v-for="(items, index) in Math.ceil(conferenceData.length / 9)"
              :key="`guests_${index}`"
            >
              <div
                v-for="(item, index) in conferenceData.slice(
                  (items - 1) * 9,
                  items * 9
                )"
                :key="index"
                class="conference-guests-item-box"
              >
                <div
                  class="conference-guests-item-img flex-column-start-end"
                  :style="{ background: 'url(' + item.picture + ')' }"
                >
                  <div class="conference-guests-item-text">
                    <div class="conference-guests-item-name">
                      {{ item.name }}
                    </div>
                    <div class="conference-guests-item-company">
                      {{ item.company }}
                    </div>
                    <div class="conference-guests-item-profession">
                      {{ item.profession }}
                    </div>
                  </div>
                </div>
              </div>
            </van-swipe-item>
          </van-swipe>
        </div>

return里声明的数据或者直接使用后台返回的数据

复制代码
 conferenceData: [
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 0,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 1,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 2,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 3,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 4,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 5,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 6,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 7,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 8,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 9,
          webGuestId: "3775644503695286273",
        },
        {
          company: "科技公司",
          name: "张三",
          pawId: "3760726639167201673",
          picture:
            "../digital_system/cbc8a90f3a6a4e699646a0d45f89a001.jpg",
          profession: "执行董事/董事长兼首席执行官",
          sort: 10,
          webGuestId: "3775644503695286273",
        },
      ], //嘉宾数据

css:

复制代码
.flex-row-wrap {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
.flex-column-start-end {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
}
.conference-guests-item-box {
    flex: 0 0 33.33%;
  }
  .conference-guests-item-img {
    width: 100%;
    height: 2.28rem;
    background-size: 100% !important;
  }
  .conference-guests-item-text {
    padding: 0 0 0.06rem 0.2rem;
    font-size: 0.12rem;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #ffffff;
    line-height: 0.16rem;
  }
  .conference-guests-item-name {
    font-size: 0.16rem;
    font-family: SourceHanSansCN-Heavy, SourceHanSansCN;
    font-weight: 800;
    color: #ffffff;
    line-height: 0.23rem;
    margin-bottom: 0.08rem;
  }

效果图:

html:

cnLeftItem:[]为后台返回数据

复制代码
      <van-swipe
              class="com-long-swipe-indicator"
              :loop="false"
              :width="swipeWidth"
            >
              <van-swipe-item v-for="item in cnLeftItem" :key="item.webNewsId">
                <a
                  :href="item.jumpLink || 'javascript:;'"
                  target="_blank"
                  class="report-item default-bg"
                  :style="{
                    'background-image': `url(${item.cover})`,
                  }"
                >
                  <span class="report-item-news-title van-multi-ellipsis--l2">
                    {{ item.newsTitle }}
                  </span>
                </a></van-swipe-item
              >
            </van-swipe>

js:

复制代码
  created() {
    //一定要写在created里,在数据渲染完成之前拿到屏幕宽度
    this.bodyWidth = window.innerWidth;
    this.swipeWidth = window.innerWidth * 0.3946;
  },
相关推荐
艾小码几秒前
为什么你的JavaScript代码总是出bug?这5个隐藏陷阱太坑了!
前端·javascript
辻戋2 小时前
从零实现React Scheduler调度器
前端·react.js·前端框架
徐同保2 小时前
使用yarn@4.6.0装包,项目是react+vite搭建的,项目无法启动,报错:
前端·react.js·前端框架
Qrun3 小时前
Windows11安装nvm管理node多版本
前端·vscode·react.js·ajax·npm·html5
中国lanwp3 小时前
全局 npm config 与多环境配置
前端·npm·node.js
JELEE.4 小时前
Django登录注册完整代码(图片、邮箱验证、加密)
前端·javascript·后端·python·django·bootstrap·jquery
TeleostNaCl6 小时前
解决 Chrome 无法访问网页但无痕模式下可以访问该网页 的问题
前端·网络·chrome·windows·经验分享
前端大卫7 小时前
为什么 React 中的 key 不能用索引?
前端
你的人类朋友7 小时前
【Node】手动归还主线程控制权:解决 Node.js 阻塞的一个思路
前端·后端·node.js
小李小李不讲道理9 小时前
「Ant Design 组件库探索」五:Tabs组件
前端·react.js·ant design