vue2+vant+h5中轮播图van-swipe指示器样式更改

7 篇文章 0 订阅
4 篇文章 0 订阅

在这里插入图片描述
组件默认指示器样式是圆点,有的时候ui设计的并不是,此时就需要我们去更改样式。或者自定义指示器了。

<template>
  <div class="home-page">
    <van-swipe :loop="false">
      <van-swipe-item>1</van-swipe-item>
      <van-swipe-item>2</van-swipe-item>
    </van-swipe>
    </div>
</template>
...
<style lang="less" scoped>
/deep/ .van-swipe{
	width:700px;
	height:150px;
	line-height: 150px;
    color: #fff;
    font-size: 20px;
    text-align: center;
    background-color: #001f32;
    // 指示器整体样式
    &__indicators {
      left:8%;
    }
    // // 单个指示器样式,默认opacity: 0.3;
    &__indicator {
      background-color: #B5BBDA;
      border-radius: 0%;
      //指示器间距
      &:not(:last-child) {
        margin-right: 10px;
      }
      // 选中的指示器样式,也可在标签中直接加indicator-color="white"
      &--active {
        background-color:#B5BBDA;
        width:20px;
        opacity:1;
      }
    }
}
</style>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现滚动到底部加载下一页数据,可以使用 `van-list` 的 `@scroll.native` 事件来监听滚动事件,然后通过计算列表高度和滚动高度来判断是否滚动到了底部。 具体实现步骤如下: 1. 给 `van-list` 组件添加 `ref` 属性,用于获取组件实例。 ```html <van-list ref="list" :finished="isFinished" :loading="isLoading" @load="onLoad"> ... </van-list> ``` 2. 在 `mounted` 钩子函数,获取 `van-list` 组件实例,并给 `window` 对象添加 `scroll` 事件监听器。 ```typescript import { defineComponent, onMounted, ref } from 'vue'; import { List } from 'vant'; export default defineComponent({ components: { VanList }, setup() { const listRef = ref(null); onMounted(() => { const listInstance = listRef.value.$el; window.addEventListener('scroll', () => { const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; const clientHeight = document.documentElement.clientHeight || document.body.clientHeight; if (scrollTop + clientHeight >= scrollHeight && listInstance.offsetHeight) { // 滚动到底部,触发加载更多 } }); }); return { listRef, }; }, }); ``` 3. 在 `@load` 事件,将 `isFinished` 和 `isLoading` 属性设置为 `true` 和 `false`,表示数据已经加载完成或正在加载。 ```typescript export default defineComponent({ components: { VanList }, setup() { const listRef = ref(null); const isFinished = ref(false); const isLoading = ref(false); const onLoad = () => { if (!isFinished.value && !isLoading.value) { isLoading.value = true; // 发送网络请求,获取下一页数据 // 请求成功后,将 isLoading 设置为 false,表示加载完成 } }; onMounted(() => { const listInstance = listRef.value.$el; window.addEventListener('scroll', () => { const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; const clientHeight = document.documentElement.clientHeight || document.body.clientHeight; if (scrollTop + clientHeight >= scrollHeight && listInstance.offsetHeight) { onLoad(); } }); }); return { listRef, isFinished, isLoading, onLoad, }; }, }); ``` 这样,当滚动到底部时,就会触发 `onLoad` 方法,从而加载下一页数据。需要注意的是,在数据全部加载完成后,需要将 `isFinished` 设置为 `true`,以防止重复加载数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值