(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;
  },
相关推荐
我想学LINUX25 分钟前
【2024年华为OD机试】 (A卷,100分)- 微服务的集成测试(JavaScript&Java & Python&C/C++)
java·c语言·javascript·python·华为od·微服务·集成测试
screct_demo31 分钟前
詳細講一下在RN(ReactNative)中,6個比較常用的組件以及詳細的用法
javascript·react native·react.js
桂月二二6 小时前
探索前端开发中的 Web Vitals —— 提升用户体验的关键技术
前端·ux
CodeClimb7 小时前
【华为OD-E卷 - 第k个排列 100分(python、java、c++、js、c)】
java·javascript·c++·python·华为od
沈梦研7 小时前
【Vscode】Vscode不能执行vue脚本的原因及解决方法
ide·vue.js·vscode
hunter2062067 小时前
ubuntu向一个pc主机通过web发送数据,pc端通过工具直接查看收到的数据
linux·前端·ubuntu
qzhqbb7 小时前
web服务器 网站部署的架构
服务器·前端·架构
刻刻帝的海角7 小时前
CSS 颜色
前端·css
轻口味7 小时前
Vue.js 组件之间的通信模式
vue.js
九酒7 小时前
从UI稿到代码优化,看Trae AI 编辑器如何帮助开发者提效
前端·trae