(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;
  },
相关推荐
小政爱学习!19 分钟前
封装axios、环境变量、api解耦、解决跨域、全局组件注入
开发语言·前端·javascript
魏大帅。25 分钟前
Axios 的 responseType 属性详解及 Blob 与 ArrayBuffer 解析
前端·javascript·ajax
花花鱼31 分钟前
vue3 基于element-plus进行的一个可拖动改变导航与内容区域大小的简单方法
前端·javascript·elementui
k093335 分钟前
sourceTree回滚版本到某次提交
开发语言·前端·javascript
EricWang13581 小时前
[OS] 项目三-2-proc.c: exit(int status)
服务器·c语言·前端
September_ning1 小时前
React.lazy() 懒加载
前端·react.js·前端框架
web行路人1 小时前
React中类组件和函数组件的理解和区别
前端·javascript·react.js·前端框架
番茄小酱0011 小时前
Expo|ReactNative 中实现扫描二维码功能
javascript·react native·react.js
子非鱼9211 小时前
【Ajax】跨域
javascript·ajax·cors·jsonp
超雄代码狂1 小时前
ajax关于axios库的运用小案例
前端·javascript·ajax