m0_65213775 2022-06-12 21:56 采纳率: 90.5%
浏览 104
已结题

指导下Vant轮播图封装!

Vant轮播图库
<template>
  <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
    <van-swipe-item class="my-swipeitem"><slot></slot></van-swipe-item>
  </van-swipe>
</template>

<script>
import { Swipe, SwipeItem } from "./Swipe";

export default {
  name: "Swipe",
  components: {
    Swipe,
    SwipeItem,
  },
}
</script>

<style scoped>
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
</style>

<template>
  <Swipe>
    <slot v-for="item in swipebannar"><img :src="item.image" alt="" /></slot>
  </Swipe>
</template>

<script>
import Swipe from "../../../components/content/swipe/Swipe.vue";

export default {
  name: "HomeSwipe",
  components: {
    Swipe,
  },
  props: {
    swipebannar: {
      type: Array,
      default() {
        return [];
      }
    }
  }
}
</script>

<style scoped>
.my-swipeitem img {
  width: 100%;
  height: 100%;
}

</style>

谁能指导下怎么把第一个Vant轮播图的ui库,封到第二个Swipe组件里面不。
我把数据传到vant库里面是能正常显示的,但是我自己封的轮播图竖着排一排,也不滚动。

  • 写回答

2条回答 默认 最新

  • Heerey525 前端领域新星创作者 2022-06-13 09:42
    关注

    这是因为插槽的位置只有一个,你遍历扔进去三个,而且还在父组件中又弄了插槽
    可以改成,Swipe通过props接收一个数组,内部遍历生成多个van-swipe-item,父组件把swipebannar传入

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月21日
  • 已采纳回答 6月13日
  • 创建了问题 6月12日

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘